@tanstack/router-core 1.161.1 → 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 +24 -20
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/router.js +24 -20
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +29 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-core",
|
|
3
|
-
"version": "1.161.
|
|
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
|
@@ -871,6 +871,13 @@ export function getLocationChangeInfo(routerState: {
|
|
|
871
871
|
return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged }
|
|
872
872
|
}
|
|
873
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
|
+
|
|
874
881
|
export type CreateRouterFn = <
|
|
875
882
|
TRouteTree extends AnyRoute,
|
|
876
883
|
TTrailingSlashOption extends TrailingSlashOption = 'never',
|
|
@@ -1123,16 +1130,7 @@ export class RouterCore<
|
|
|
1123
1130
|
getInitialRouterState(this.latestLocation),
|
|
1124
1131
|
) as unknown as Store<any>
|
|
1125
1132
|
} else {
|
|
1126
|
-
this.__store = new Store(getInitialRouterState(this.latestLocation)
|
|
1127
|
-
onUpdate: () => {
|
|
1128
|
-
this.__store.state = {
|
|
1129
|
-
...this.state,
|
|
1130
|
-
cachedMatches: this.state.cachedMatches.filter(
|
|
1131
|
-
(d) => !['redirected'].includes(d.status),
|
|
1132
|
-
),
|
|
1133
|
-
}
|
|
1134
|
-
},
|
|
1135
|
-
})
|
|
1133
|
+
this.__store = new Store(getInitialRouterState(this.latestLocation))
|
|
1136
1134
|
|
|
1137
1135
|
setupScrollRestoration(this)
|
|
1138
1136
|
}
|
|
@@ -1175,10 +1173,10 @@ export class RouterCore<
|
|
|
1175
1173
|
}
|
|
1176
1174
|
|
|
1177
1175
|
if (needsLocationUpdate && this.__store) {
|
|
1178
|
-
this.__store.
|
|
1179
|
-
...
|
|
1176
|
+
this.__store.setState((s) => ({
|
|
1177
|
+
...s,
|
|
1180
1178
|
location: this.latestLocation,
|
|
1181
|
-
}
|
|
1179
|
+
}))
|
|
1182
1180
|
}
|
|
1183
1181
|
|
|
1184
1182
|
if (
|
|
@@ -2445,7 +2443,9 @@ export class RouterCore<
|
|
|
2445
2443
|
...s.cachedMatches,
|
|
2446
2444
|
...exitingMatches.filter(
|
|
2447
2445
|
(d) =>
|
|
2448
|
-
d.status !== 'error' &&
|
|
2446
|
+
d.status !== 'error' &&
|
|
2447
|
+
d.status !== 'notFound' &&
|
|
2448
|
+
d.status !== 'redirected',
|
|
2449
2449
|
),
|
|
2450
2450
|
],
|
|
2451
2451
|
}
|
|
@@ -2600,12 +2600,21 @@ export class RouterCore<
|
|
|
2600
2600
|
: ''
|
|
2601
2601
|
|
|
2602
2602
|
if (matchesKey) {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
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
|
+
}
|
|
2609
2618
|
}
|
|
2610
2619
|
})
|
|
2611
2620
|
}
|