@tanstack/react-router 1.35.2 → 1.35.3
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/dist/cjs/link.cjs +2 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/router.cjs +7 -14
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +4 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/esm/link.js +2 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.js +7 -14
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useNavigate.js +4 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/package.json +1 -1
- package/src/link.tsx +1 -0
- package/src/router.ts +6 -17
- package/src/useNavigate.tsx +2 -0
package/src/router.ts
CHANGED
|
@@ -1102,27 +1102,14 @@ 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
|
|
1111
1105
|
|
|
1112
1106
|
const fromMatches = this.matchRoutes(
|
|
1113
1107
|
this.latestLocation.pathname,
|
|
1114
1108
|
fromSearch,
|
|
1115
1109
|
)
|
|
1116
1110
|
|
|
1117
|
-
|
|
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
|
-
|
|
1111
|
+
fromPath =
|
|
1112
|
+
fromMatches.find((d) => d.id === dest.from)?.pathname || fromPath
|
|
1126
1113
|
fromSearch = last(fromMatches)?.search || this.latestLocation.search
|
|
1127
1114
|
|
|
1128
1115
|
const stayingMatches = matches?.filter((d) =>
|
|
@@ -1786,7 +1773,8 @@ export class Router<
|
|
|
1786
1773
|
preload: !!preload,
|
|
1787
1774
|
context: parentContext,
|
|
1788
1775
|
location,
|
|
1789
|
-
navigate: (opts: any) =>
|
|
1776
|
+
navigate: (opts: any) =>
|
|
1777
|
+
this.navigate({ ...opts, from: match.pathname }),
|
|
1790
1778
|
buildLocation: this.buildLocation,
|
|
1791
1779
|
cause: preload ? 'preload' : match.cause,
|
|
1792
1780
|
})) ?? ({} as any)
|
|
@@ -1839,7 +1827,8 @@ export class Router<
|
|
|
1839
1827
|
abortController: match.abortController,
|
|
1840
1828
|
context: match.context,
|
|
1841
1829
|
location,
|
|
1842
|
-
navigate: (opts) =>
|
|
1830
|
+
navigate: (opts) =>
|
|
1831
|
+
this.navigate({ ...opts, from: match.pathname } as any),
|
|
1843
1832
|
cause: preload ? 'preload' : match.cause,
|
|
1844
1833
|
route,
|
|
1845
1834
|
}
|
package/src/useNavigate.tsx
CHANGED
|
@@ -29,6 +29,7 @@ export function useNavigate<
|
|
|
29
29
|
(options: NavigateOptions) => {
|
|
30
30
|
return router.navigate({
|
|
31
31
|
...options,
|
|
32
|
+
from: options.to ? router.state.resolvedLocation.pathname : undefined,
|
|
32
33
|
})
|
|
33
34
|
},
|
|
34
35
|
[router],
|
|
@@ -62,6 +63,7 @@ export function Navigate<
|
|
|
62
63
|
|
|
63
64
|
React.useEffect(() => {
|
|
64
65
|
navigate({
|
|
66
|
+
from: props.to ? match.pathname : undefined,
|
|
65
67
|
...props,
|
|
66
68
|
} as any)
|
|
67
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|