@tanstack/react-router 1.36.1 → 1.36.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/Transitioner.cjs +1 -1
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/link.cjs +0 -5
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/router.cjs +19 -18
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/Transitioner.js +1 -1
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/link.js +0 -5
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.js +19 -18
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/Transitioner.tsx +1 -1
- package/src/link.tsx +0 -4
- package/src/router.ts +37 -23
package/src/router.ts
CHANGED
|
@@ -1101,12 +1101,22 @@ export class Router<
|
|
|
1101
1101
|
} = {},
|
|
1102
1102
|
matches?: Array<MakeRouteMatch<TRouteTree>>,
|
|
1103
1103
|
): ParsedLocation => {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1104
|
+
// if the router is loading the previous location is what
|
|
1105
|
+
// we should use because the old matches are still around
|
|
1106
|
+
// and the latest location has already been updated.
|
|
1107
|
+
// If the router is not loading we should always use the
|
|
1108
|
+
// latest location because resolvedLocation can lag behind
|
|
1109
|
+
// and the new matches could already render
|
|
1110
|
+
const currentLocation = this.state.isLoading
|
|
1111
|
+
? this.state.resolvedLocation
|
|
1112
|
+
: this.latestLocation
|
|
1108
1113
|
|
|
1109
|
-
const
|
|
1114
|
+
const location = dest._fromLocation ?? currentLocation
|
|
1115
|
+
|
|
1116
|
+
let fromPath = location.pathname
|
|
1117
|
+
let fromSearch = dest.fromSearch || location.search
|
|
1118
|
+
|
|
1119
|
+
const fromMatches = this.matchRoutes(location.pathname, fromSearch)
|
|
1110
1120
|
|
|
1111
1121
|
const fromMatch =
|
|
1112
1122
|
dest.from != null
|
|
@@ -1548,7 +1558,7 @@ export class Router<
|
|
|
1548
1558
|
redirect = err
|
|
1549
1559
|
if (!this.isServer) {
|
|
1550
1560
|
this.navigate({ ...err, replace: true, __isRedirect: true })
|
|
1551
|
-
this.load()
|
|
1561
|
+
// this.load()
|
|
1552
1562
|
}
|
|
1553
1563
|
} else if (isNotFound(err)) {
|
|
1554
1564
|
notFound = err
|
|
@@ -1773,28 +1783,32 @@ export class Router<
|
|
|
1773
1783
|
parentMatch?.context ?? this.options.context ?? {}
|
|
1774
1784
|
|
|
1775
1785
|
// Make sure the match has parent context set before going further
|
|
1776
|
-
matches[index] = match =
|
|
1786
|
+
matches[index] = match = {
|
|
1777
1787
|
...match,
|
|
1778
1788
|
routeContext: replaceEqualDeep(
|
|
1779
1789
|
match.routeContext,
|
|
1780
1790
|
parentContext,
|
|
1781
1791
|
),
|
|
1792
|
+
context: replaceEqualDeep(match.context, parentContext),
|
|
1782
1793
|
abortController,
|
|
1783
|
-
}
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
const beforeLoadFnContext = {
|
|
1797
|
+
search: match.search,
|
|
1798
|
+
abortController,
|
|
1799
|
+
params: match.params,
|
|
1800
|
+
preload: !!preload,
|
|
1801
|
+
context: match.routeContext,
|
|
1802
|
+
location,
|
|
1803
|
+
navigate: (opts: any) =>
|
|
1804
|
+
this.navigate({ ...opts, _fromLocation: location }),
|
|
1805
|
+
buildLocation: this.buildLocation,
|
|
1806
|
+
cause: preload ? 'preload' : match.cause,
|
|
1807
|
+
}
|
|
1784
1808
|
|
|
1785
|
-
const beforeLoadContext =
|
|
1786
|
-
(await route.options.beforeLoad
|
|
1787
|
-
|
|
1788
|
-
abortController,
|
|
1789
|
-
params: match.params,
|
|
1790
|
-
preload: !!preload,
|
|
1791
|
-
context: parentContext,
|
|
1792
|
-
location,
|
|
1793
|
-
navigate: (opts: any) =>
|
|
1794
|
-
this.navigate({ ...opts, _fromLocation: location }),
|
|
1795
|
-
buildLocation: this.buildLocation,
|
|
1796
|
-
cause: preload ? 'preload' : match.cause,
|
|
1797
|
-
})) ?? ({} as any)
|
|
1809
|
+
const beforeLoadContext = route.options.beforeLoad
|
|
1810
|
+
? (await route.options.beforeLoad(beforeLoadFnContext)) ?? {}
|
|
1811
|
+
: {}
|
|
1798
1812
|
|
|
1799
1813
|
checkLatest()
|
|
1800
1814
|
|
|
@@ -1850,7 +1864,7 @@ export class Router<
|
|
|
1850
1864
|
route,
|
|
1851
1865
|
}
|
|
1852
1866
|
|
|
1853
|
-
const
|
|
1867
|
+
const fetchAndResolveInLoaderLifetime = async () => {
|
|
1854
1868
|
const existing = getRouteMatch(this.state, match.id)!
|
|
1855
1869
|
let lazyPromise = Promise.resolve()
|
|
1856
1870
|
let componentsPromise = Promise.resolve() as Promise<any>
|
|
@@ -2025,7 +2039,7 @@ export class Router<
|
|
|
2025
2039
|
|
|
2026
2040
|
const fetchWithRedirectAndNotFound = async () => {
|
|
2027
2041
|
try {
|
|
2028
|
-
await
|
|
2042
|
+
await fetchAndResolveInLoaderLifetime()
|
|
2029
2043
|
} catch (err) {
|
|
2030
2044
|
checkLatest()
|
|
2031
2045
|
handleRedirectAndNotFound(match, err)
|