diff --git a/packages/solid-router/src/link.tsx b/packages/solid-router/src/link.tsx index f9bd2df954f..0e4d4f4f494 100644 --- a/packages/solid-router/src/link.tsx +++ b/packages/solid-router/src/link.tsx @@ -122,16 +122,20 @@ export function useLinkProps< 'unsafeRelative', ]) - const currentLocation = Solid.createMemo(() => router.stores.location.state) - const currentSearch = Solid.createMemo( - () => router.stores.location.state.searchStr, + const buildLocationKey = Solid.createMemo( + () => + router.stores.lastMatchId.state + + '\0' + + router.stores.location.state.hash + + '\0' + + router.stores.location.state.searchStr, ) const _options = () => options const next = Solid.createMemo(() => { - // rebuild location when search changes - currentSearch() + // Rebuild when inherited search/hash or the current route context changes. + buildLocationKey() const options = _options() as any // untrack because router-core will also access stores, which are signals in solid return Solid.untrack(() => router.buildLocation(options)) @@ -199,7 +203,7 @@ export function useLinkProps< const isActive = Solid.createMemo(() => { if (externalLink()) return false const activeOptions = local.activeOptions - const current = currentLocation() + const current = router.stores.location.state const nextLocation = next() if (activeOptions?.exact) { diff --git a/packages/vue-router/src/link.tsx b/packages/vue-router/src/link.tsx index da9224fd357..64f57a68868 100644 --- a/packages/vue-router/src/link.tsx +++ b/packages/vue-router/src/link.tsx @@ -219,6 +219,14 @@ export function useLinkProps< (location) => location.searchStr, { equal: Object.is }, ) + const currentHash = useStore( + router.stores.location, + (location) => location.hash, + { + equal: Object.is, + }, + ) + const currentLeafMatchId = useStore(router.stores.lastMatchId, (id) => id) const from = options.from ? Vue.computed(() => options.from) : useStore(router.stores.lastMatchRouteFullPath, (fullPath) => fullPath) @@ -229,8 +237,10 @@ export function useLinkProps< })) const next = Vue.computed(() => { - // Depend on search to rebuild when search changes + // Rebuild when inherited search/hash or the current route context changes. currentSearch.value + currentHash.value + currentLeafMatchId.value return router.buildLocation(_options.value as any) })