@tanstack/router-core 1.160.0 → 1.161.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/router.cjs +25 -21
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -1
- package/dist/esm/router.d.ts +1 -1
- package/dist/esm/router.js +25 -21
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +37 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.161.3",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"node": ">=12"
|
|
145
145
|
},
|
|
146
146
|
"dependencies": {
|
|
147
|
-
"@tanstack/store": "^0.
|
|
147
|
+
"@tanstack/store": "^0.9.1",
|
|
148
148
|
"cookie-es": "^2.0.0",
|
|
149
149
|
"seroval": "^1.4.2",
|
|
150
150
|
"seroval-plugins": "^1.4.2",
|
package/src/router.ts
CHANGED
|
@@ -661,7 +661,13 @@ export type PreloadRouteFn<
|
|
|
661
661
|
TTo,
|
|
662
662
|
TMaskFrom,
|
|
663
663
|
TMaskTo
|
|
664
|
-
|
|
664
|
+
> & {
|
|
665
|
+
/**
|
|
666
|
+
* @internal
|
|
667
|
+
* A **trusted** built location that can be used to redirect to.
|
|
668
|
+
*/
|
|
669
|
+
_builtLocation?: ParsedLocation
|
|
670
|
+
},
|
|
665
671
|
) => Promise<Array<AnyRouteMatch> | undefined>
|
|
666
672
|
|
|
667
673
|
export type MatchRouteFn<
|
|
@@ -865,6 +871,13 @@ export function getLocationChangeInfo(routerState: {
|
|
|
865
871
|
return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged }
|
|
866
872
|
}
|
|
867
873
|
|
|
874
|
+
function filterRedirectedCachedMatches<T extends { status: string }>(
|
|
875
|
+
matches: Array<T>,
|
|
876
|
+
): Array<T> {
|
|
877
|
+
const filtered = matches.filter((d) => d.status !== 'redirected')
|
|
878
|
+
return filtered.length === matches.length ? matches : filtered
|
|
879
|
+
}
|
|
880
|
+
|
|
868
881
|
export type CreateRouterFn = <
|
|
869
882
|
TRouteTree extends AnyRoute,
|
|
870
883
|
TTrailingSlashOption extends TrailingSlashOption = 'never',
|
|
@@ -1117,16 +1130,7 @@ export class RouterCore<
|
|
|
1117
1130
|
getInitialRouterState(this.latestLocation),
|
|
1118
1131
|
) as unknown as Store<any>
|
|
1119
1132
|
} else {
|
|
1120
|
-
this.__store = new Store(getInitialRouterState(this.latestLocation)
|
|
1121
|
-
onUpdate: () => {
|
|
1122
|
-
this.__store.state = {
|
|
1123
|
-
...this.state,
|
|
1124
|
-
cachedMatches: this.state.cachedMatches.filter(
|
|
1125
|
-
(d) => !['redirected'].includes(d.status),
|
|
1126
|
-
),
|
|
1127
|
-
}
|
|
1128
|
-
},
|
|
1129
|
-
})
|
|
1133
|
+
this.__store = new Store(getInitialRouterState(this.latestLocation))
|
|
1130
1134
|
|
|
1131
1135
|
setupScrollRestoration(this)
|
|
1132
1136
|
}
|
|
@@ -1169,10 +1173,10 @@ export class RouterCore<
|
|
|
1169
1173
|
}
|
|
1170
1174
|
|
|
1171
1175
|
if (needsLocationUpdate && this.__store) {
|
|
1172
|
-
this.__store.
|
|
1173
|
-
...
|
|
1176
|
+
this.__store.setState((s) => ({
|
|
1177
|
+
...s,
|
|
1174
1178
|
location: this.latestLocation,
|
|
1175
|
-
}
|
|
1179
|
+
}))
|
|
1176
1180
|
}
|
|
1177
1181
|
|
|
1178
1182
|
if (
|
|
@@ -2439,7 +2443,9 @@ export class RouterCore<
|
|
|
2439
2443
|
...s.cachedMatches,
|
|
2440
2444
|
...exitingMatches.filter(
|
|
2441
2445
|
(d) =>
|
|
2442
|
-
d.status !== 'error' &&
|
|
2446
|
+
d.status !== 'error' &&
|
|
2447
|
+
d.status !== 'notFound' &&
|
|
2448
|
+
d.status !== 'redirected',
|
|
2443
2449
|
),
|
|
2444
2450
|
],
|
|
2445
2451
|
}
|
|
@@ -2594,12 +2600,21 @@ export class RouterCore<
|
|
|
2594
2600
|
: ''
|
|
2595
2601
|
|
|
2596
2602
|
if (matchesKey) {
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
+
if (matchesKey === 'cachedMatches') {
|
|
2604
|
+
this.__store.setState((s) => ({
|
|
2605
|
+
...s,
|
|
2606
|
+
cachedMatches: filterRedirectedCachedMatches(
|
|
2607
|
+
s.cachedMatches.map((d) => (d.id === id ? updater(d) : d)),
|
|
2608
|
+
),
|
|
2609
|
+
}))
|
|
2610
|
+
} else {
|
|
2611
|
+
this.__store.setState((s) => ({
|
|
2612
|
+
...s,
|
|
2613
|
+
[matchesKey]: s[matchesKey]?.map((d) =>
|
|
2614
|
+
d.id === id ? updater(d) : d,
|
|
2615
|
+
),
|
|
2616
|
+
}))
|
|
2617
|
+
}
|
|
2603
2618
|
}
|
|
2604
2619
|
})
|
|
2605
2620
|
}
|
|
@@ -2757,7 +2772,7 @@ export class RouterCore<
|
|
|
2757
2772
|
TDefaultStructuralSharingOption,
|
|
2758
2773
|
TRouterHistory
|
|
2759
2774
|
> = async (opts) => {
|
|
2760
|
-
const next = this.buildLocation(opts as any)
|
|
2775
|
+
const next = opts._builtLocation ?? this.buildLocation(opts as any)
|
|
2761
2776
|
|
|
2762
2777
|
let matches = this.matchRoutes(next, {
|
|
2763
2778
|
throwOnError: true,
|