@tanstack/router-core 1.162.9 → 1.163.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 +18 -10
- 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 +19 -11
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +29 -11
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStore } from '@tanstack/store'
|
|
2
2
|
import { createBrowserHistory, parseHref } from '@tanstack/history'
|
|
3
3
|
import { isServer } from '@tanstack/router-core/isServer'
|
|
4
4
|
import { batch } from './utils/batch'
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
executeRewriteOutput,
|
|
43
43
|
rewriteBasepath,
|
|
44
44
|
} from './rewrite'
|
|
45
|
+
import type { Store } from '@tanstack/store'
|
|
45
46
|
import type { LRUCache } from './lru-cache'
|
|
46
47
|
import type {
|
|
47
48
|
ProcessRouteTreeResult,
|
|
@@ -1132,7 +1133,7 @@ export class RouterCore<
|
|
|
1132
1133
|
getInitialRouterState(this.latestLocation),
|
|
1133
1134
|
) as unknown as Store<any>
|
|
1134
1135
|
} else {
|
|
1135
|
-
this.__store =
|
|
1136
|
+
this.__store = createStore(getInitialRouterState(this.latestLocation))
|
|
1136
1137
|
|
|
1137
1138
|
setupScrollRestoration(this)
|
|
1138
1139
|
}
|
|
@@ -2405,9 +2406,16 @@ export class RouterCore<
|
|
|
2405
2406
|
|
|
2406
2407
|
// Commit the pending matches. If a previous match was
|
|
2407
2408
|
// removed, place it in the cachedMatches
|
|
2409
|
+
//
|
|
2410
|
+
// exitingMatches uses match.id (routeId + params + loaderDeps) so
|
|
2411
|
+
// navigating /foo?page=1 → /foo?page=2 correctly caches the page=1 entry.
|
|
2408
2412
|
let exitingMatches: Array<AnyRouteMatch> = []
|
|
2409
|
-
|
|
2410
|
-
|
|
2413
|
+
|
|
2414
|
+
// Lifecycle-hook identity uses routeId only so that navigating between
|
|
2415
|
+
// different params/deps of the same route fires onStay (not onLeave+onEnter).
|
|
2416
|
+
let hookExitingMatches: Array<AnyRouteMatch> = []
|
|
2417
|
+
let hookEnteringMatches: Array<AnyRouteMatch> = []
|
|
2418
|
+
let hookStayingMatches: Array<AnyRouteMatch> = []
|
|
2411
2419
|
|
|
2412
2420
|
batch(() => {
|
|
2413
2421
|
this.__store.setState((s) => {
|
|
@@ -2417,12 +2425,22 @@ export class RouterCore<
|
|
|
2417
2425
|
exitingMatches = previousMatches.filter(
|
|
2418
2426
|
(match) => !newMatches.some((d) => d.id === match.id),
|
|
2419
2427
|
)
|
|
2420
|
-
|
|
2428
|
+
|
|
2429
|
+
// Lifecycle-hook identity: routeId only (route presence in tree)
|
|
2430
|
+
hookExitingMatches = previousMatches.filter(
|
|
2431
|
+
(match) =>
|
|
2432
|
+
!newMatches.some((d) => d.routeId === match.routeId),
|
|
2433
|
+
)
|
|
2434
|
+
hookEnteringMatches = newMatches.filter(
|
|
2421
2435
|
(match) =>
|
|
2422
|
-
!previousMatches.some(
|
|
2436
|
+
!previousMatches.some(
|
|
2437
|
+
(d) => d.routeId === match.routeId,
|
|
2438
|
+
),
|
|
2423
2439
|
)
|
|
2424
|
-
|
|
2425
|
-
previousMatches.some(
|
|
2440
|
+
hookStayingMatches = newMatches.filter((match) =>
|
|
2441
|
+
previousMatches.some(
|
|
2442
|
+
(d) => d.routeId === match.routeId,
|
|
2443
|
+
),
|
|
2426
2444
|
)
|
|
2427
2445
|
|
|
2428
2446
|
return {
|
|
@@ -2454,9 +2472,9 @@ export class RouterCore<
|
|
|
2454
2472
|
//
|
|
2455
2473
|
;(
|
|
2456
2474
|
[
|
|
2457
|
-
[
|
|
2458
|
-
[
|
|
2459
|
-
[
|
|
2475
|
+
[hookExitingMatches, 'onLeave'],
|
|
2476
|
+
[hookEnteringMatches, 'onEnter'],
|
|
2477
|
+
[hookStayingMatches, 'onStay'],
|
|
2460
2478
|
] as const
|
|
2461
2479
|
).forEach(([matches, hook]) => {
|
|
2462
2480
|
matches.forEach((match) => {
|