@tanstack/react-router 1.35.5 → 1.35.6

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
@@ -585,11 +585,6 @@ export function useLinkProps<
585
585
  // If this `to` is a valid external URL, return
586
586
  // null for LinkUtils
587
587
 
588
- const dest = {
589
- ...(options.to && { from: matchPathname }),
590
- ...options,
591
- }
592
-
593
588
  let type: 'internal' | 'external' = 'internal'
594
589
 
595
590
  try {
@@ -597,7 +592,7 @@ export function useLinkProps<
597
592
  type = 'external'
598
593
  } catch {}
599
594
 
600
- const next = router.buildLocation(dest as any)
595
+ const next = router.buildLocation(options as any)
601
596
  const preload = userPreload ?? router.options.defaultPreload
602
597
  const preloadDelay =
603
598
  userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0
@@ -683,7 +678,7 @@ export function useLinkProps<
683
678
  }
684
679
 
685
680
  const doPreload = () => {
686
- router.preloadRoute(dest as any).catch((err) => {
681
+ router.preloadRoute(options as any).catch((err) => {
687
682
  console.warn(err)
688
683
  console.warn(preloadWarning)
689
684
  })
package/src/router.ts CHANGED
@@ -380,6 +380,7 @@ export interface BuildNextOptions {
380
380
  }
381
381
  from?: string
382
382
  fromSearch?: unknown
383
+ _fromLocation?: ParsedLocation
383
384
  }
384
385
 
385
386
  export interface DehydratedRouterState {
@@ -1100,16 +1101,31 @@ export class Router<
1100
1101
  } = {},
1101
1102
  matches?: Array<MakeRouteMatch<TRouteTree>>,
1102
1103
  ): ParsedLocation => {
1103
- let fromPath = this.latestLocation.pathname
1104
- let fromSearch = dest.fromSearch || this.latestLocation.search
1104
+ const latestLocation =
1105
+ dest._fromLocation ?? (this.latestLocation as ParsedLocation)
1106
+ let fromPath = latestLocation.pathname
1107
+ let fromSearch = dest.fromSearch || latestLocation.search
1108
+
1109
+ const fromMatches = this.matchRoutes(latestLocation.pathname, fromSearch)
1110
+
1111
+ const fromMatch =
1112
+ dest.from != null
1113
+ ? fromMatches.find((d) =>
1114
+ matchPathname(this.basepath, trimPathRight(d.pathname), {
1115
+ to: dest.from,
1116
+ caseSensitive: false,
1117
+ fuzzy: false,
1118
+ }),
1119
+ )
1120
+ : undefined
1121
+
1122
+ fromPath = fromMatch?.pathname || fromPath
1105
1123
 
1106
- const fromMatches = this.matchRoutes(
1107
- this.latestLocation.pathname,
1108
- fromSearch,
1124
+ invariant(
1125
+ dest.from == null || fromMatch != null,
1126
+ 'Could not find match for from: ' + dest.from,
1109
1127
  )
1110
1128
 
1111
- fromPath =
1112
- fromMatches.find((d) => d.id === dest.from)?.pathname || fromPath
1113
1129
  fromSearch = last(fromMatches)?.search || this.latestLocation.search
1114
1130
 
1115
1131
  const stayingMatches = matches?.filter((d) =>
@@ -1260,9 +1276,10 @@ export class Router<
1260
1276
  })
1261
1277
 
1262
1278
  if (foundMask) {
1279
+ const { from, ...maskProps } = foundMask
1263
1280
  maskedDest = {
1264
1281
  ...pick(opts, ['from']),
1265
- ...foundMask,
1282
+ ...maskProps,
1266
1283
  params,
1267
1284
  }
1268
1285
  maskedNext = build(maskedDest)
@@ -1774,7 +1791,7 @@ export class Router<
1774
1791
  context: parentContext,
1775
1792
  location,
1776
1793
  navigate: (opts: any) =>
1777
- this.navigate({ ...opts, from: match.pathname }),
1794
+ this.navigate({ ...opts, _fromLocation: location }),
1778
1795
  buildLocation: this.buildLocation,
1779
1796
  cause: preload ? 'preload' : match.cause,
1780
1797
  })) ?? ({} as any)
@@ -1828,7 +1845,7 @@ export class Router<
1828
1845
  context: match.context,
1829
1846
  location,
1830
1847
  navigate: (opts) =>
1831
- this.navigate({ ...opts, from: match.pathname } as any),
1848
+ this.navigate({ ...opts, _fromLocation: location }),
1832
1849
  cause: preload ? 'preload' : match.cause,
1833
1850
  route,
1834
1851
  }
@@ -2183,9 +2200,8 @@ export class Router<
2183
2200
  } catch (err) {
2184
2201
  if (isRedirect(err)) {
2185
2202
  return await this.preloadRoute({
2186
- fromSearch: next.search,
2187
- from: next.pathname,
2188
2203
  ...(err as any),
2204
+ _fromLocation: next,
2189
2205
  })
2190
2206
  }
2191
2207
  // Preload errors are not fatal, but we should still log them
@@ -29,7 +29,6 @@ export function useNavigate<
29
29
  (options: NavigateOptions) => {
30
30
  return router.navigate({
31
31
  ...options,
32
- from: options.to ? router.state.resolvedLocation.pathname : undefined,
33
32
  })
34
33
  },
35
34
  [router],
@@ -63,7 +62,6 @@ export function Navigate<
63
62
 
64
63
  React.useEffect(() => {
65
64
  navigate({
66
- from: props.to ? match.pathname : undefined,
67
65
  ...props,
68
66
  } as any)
69
67
  // eslint-disable-next-line react-hooks/exhaustive-deps