@tanstack/react-router 1.35.0 → 1.35.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/router.ts CHANGED
@@ -1102,14 +1102,27 @@ export class Router<
1102
1102
  ): ParsedLocation => {
1103
1103
  let fromPath = this.latestLocation.pathname
1104
1104
  let fromSearch = dest.fromSearch || this.latestLocation.search
1105
+ const looseRoutesByPath = this.routesByPath as Record<string, AnyRoute>
1106
+
1107
+ const fromRoute =
1108
+ dest.from !== undefined
1109
+ ? looseRoutesByPath[trimPathRight(dest.from)]
1110
+ : undefined
1105
1111
 
1106
1112
  const fromMatches = this.matchRoutes(
1107
1113
  this.latestLocation.pathname,
1108
1114
  fromSearch,
1109
1115
  )
1110
1116
 
1111
- fromPath =
1112
- fromMatches.find((d) => d.id === dest.from)?.pathname || fromPath
1117
+ const fromMatch = fromMatches.find((d) => d.routeId === fromRoute?.id)
1118
+
1119
+ fromPath = fromMatch?.pathname || fromPath
1120
+
1121
+ invariant(
1122
+ dest.from == null || fromMatch != null,
1123
+ 'Could not find match for from: ' + dest.from,
1124
+ )
1125
+
1113
1126
  fromSearch = last(fromMatches)?.search || this.latestLocation.search
1114
1127
 
1115
1128
  const stayingMatches = matches?.filter((d) =>
@@ -1773,8 +1786,7 @@ export class Router<
1773
1786
  preload: !!preload,
1774
1787
  context: parentContext,
1775
1788
  location,
1776
- navigate: (opts: any) =>
1777
- this.navigate({ ...opts, from: match.pathname }),
1789
+ navigate: (opts: any) => this.navigate({ ...opts }),
1778
1790
  buildLocation: this.buildLocation,
1779
1791
  cause: preload ? 'preload' : match.cause,
1780
1792
  })) ?? ({} as any)
@@ -1827,8 +1839,7 @@ export class Router<
1827
1839
  abortController: match.abortController,
1828
1840
  context: match.context,
1829
1841
  location,
1830
- navigate: (opts) =>
1831
- this.navigate({ ...opts, from: match.pathname } as any),
1842
+ navigate: (opts) => this.navigate({ ...opts } as any),
1832
1843
  cause: preload ? 'preload' : match.cause,
1833
1844
  route,
1834
1845
  }
@@ -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