Fix using screen names in Link (#8473)

* use our router in favour of useLinkBuilder

* test feature using Home header feeds button

* handle non-string params properly
This commit is contained in:
Samuel Newman
2025-06-11 20:12:05 +03:00
committed by GitHub
parent 269105371b
commit 7341294df6
4 changed files with 11 additions and 21 deletions
+3 -5
View File
@@ -4,7 +4,6 @@ import {sanitizeUrl} from '@braintree/sanitize-url'
import {
type LinkProps as RNLinkProps,
StackActions,
useLinkBuilder,
} from '@react-navigation/native'
import {BSKY_DOWNLOAD_URL} from '#/lib/constants'
@@ -95,20 +94,19 @@ export function useLink({
shouldProxy?: boolean
}) {
const navigation = useNavigationDeduped()
const {buildHref} = useLinkBuilder()
const href = useMemo(() => {
return typeof to === 'string'
? convertBskyAppUrlIfNeeded(sanitizeUrl(to))
: to.screen
? buildHref(to.screen, to.params)
? router.matchName(to.screen)?.build(to.params)
: to.href
? convertBskyAppUrlIfNeeded(sanitizeUrl(to.href))
: undefined
}, [to, buildHref])
}, [to])
if (!href) {
throw new Error(
'Link `to` prop must be a string or an object with `screen` and `params` properties',
'Could not resolve screen. Link `to` prop must be a string or an object with `screen` and `params` properties',
)
}