@tanstack/react-router 1.160.0 → 1.161.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/link.tsx CHANGED
@@ -376,10 +376,17 @@ export function useLinkProps<
376
376
  // eslint-disable-next-line react-hooks/rules-of-hooks
377
377
  const isHydrated = useHydrated()
378
378
 
379
- // subscribe to search params to re-build location if it changes
379
+ // subscribe to path/search/hash/params to re-build location when they change
380
380
  // eslint-disable-next-line react-hooks/rules-of-hooks
381
- const currentSearch = useRouterState({
382
- select: (s) => s.location.search,
381
+ const currentLocationState = useRouterState({
382
+ select: (s) => {
383
+ const leaf = s.matches[s.matches.length - 1]
384
+ return {
385
+ search: leaf?.search,
386
+ hash: s.location.hash,
387
+ path: leaf?.pathname, // path + params
388
+ }
389
+ },
383
390
  structuralSharing: true as any,
384
391
  })
385
392
 
@@ -393,7 +400,7 @@ export function useLinkProps<
393
400
  // eslint-disable-next-line react-hooks/exhaustive-deps
394
401
  [
395
402
  router,
396
- currentSearch,
403
+ currentLocationState,
397
404
  from,
398
405
  options._fromLocation,
399
406
  options.hash,
@@ -556,11 +563,13 @@ export function useLinkProps<
556
563
 
557
564
  // eslint-disable-next-line react-hooks/rules-of-hooks
558
565
  const doPreload = React.useCallback(() => {
559
- router.preloadRoute({ ..._options } as any).catch((err) => {
560
- console.warn(err)
561
- console.warn(preloadWarning)
562
- })
563
- }, [router, _options])
566
+ router
567
+ .preloadRoute({ ..._options, _builtLocation: next } as any)
568
+ .catch((err) => {
569
+ console.warn(err)
570
+ console.warn(preloadWarning)
571
+ })
572
+ }, [router, _options, next])
564
573
 
565
574
  // eslint-disable-next-line react-hooks/rules-of-hooks
566
575
  const preloadViewportIoCallback = React.useCallback(