@tanstack/router-core 1.131.5 → 1.131.12
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 +73 -52
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/router.js +73 -52
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +96 -66
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -1393,8 +1393,8 @@ export class RouterCore<
|
|
|
1393
1393
|
if (!match) return
|
|
1394
1394
|
|
|
1395
1395
|
match.abortController.abort()
|
|
1396
|
-
match._nonReactive.pendingTimeout = undefined
|
|
1397
1396
|
clearTimeout(match._nonReactive.pendingTimeout)
|
|
1397
|
+
match._nonReactive.pendingTimeout = undefined
|
|
1398
1398
|
}
|
|
1399
1399
|
|
|
1400
1400
|
cancelMatches = () => {
|
|
@@ -1420,7 +1420,7 @@ export class RouterCore<
|
|
|
1420
1420
|
|
|
1421
1421
|
// First let's find the starting pathname
|
|
1422
1422
|
// By default, start with the current location
|
|
1423
|
-
let fromPath = lastMatch.fullPath
|
|
1423
|
+
let fromPath = this.resolvePathWithBase(lastMatch.fullPath, '.')
|
|
1424
1424
|
const toPath = dest.to
|
|
1425
1425
|
? this.resolvePathWithBase(fromPath, `${dest.to}`)
|
|
1426
1426
|
: this.resolvePathWithBase(fromPath, '.')
|
|
@@ -1461,6 +1461,8 @@ export class RouterCore<
|
|
|
1461
1461
|
}
|
|
1462
1462
|
}
|
|
1463
1463
|
|
|
1464
|
+
fromPath = this.resolvePathWithBase(fromPath, '.')
|
|
1465
|
+
|
|
1464
1466
|
// From search should always use the current location
|
|
1465
1467
|
const fromSearch = lastMatch.search
|
|
1466
1468
|
// Same with params. It can't hurt to provide as many as possible
|
|
@@ -2119,7 +2121,10 @@ export class RouterCore<
|
|
|
2119
2121
|
triggerOnReady()
|
|
2120
2122
|
}
|
|
2121
2123
|
|
|
2122
|
-
const handleRedirectAndNotFound = (
|
|
2124
|
+
const handleRedirectAndNotFound = (
|
|
2125
|
+
match: AnyRouteMatch | undefined,
|
|
2126
|
+
err: any,
|
|
2127
|
+
) => {
|
|
2123
2128
|
if (isRedirect(err) || isNotFound(err)) {
|
|
2124
2129
|
if (isRedirect(err)) {
|
|
2125
2130
|
if (err.redirectHandled) {
|
|
@@ -2129,27 +2134,30 @@ export class RouterCore<
|
|
|
2129
2134
|
}
|
|
2130
2135
|
}
|
|
2131
2136
|
|
|
2132
|
-
match
|
|
2133
|
-
match
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
:
|
|
2142
|
-
? '
|
|
2143
|
-
:
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2137
|
+
// in case of a redirecting match during preload, the match does not exist
|
|
2138
|
+
if (match) {
|
|
2139
|
+
match._nonReactive.beforeLoadPromise?.resolve()
|
|
2140
|
+
match._nonReactive.loaderPromise?.resolve()
|
|
2141
|
+
match._nonReactive.beforeLoadPromise = undefined
|
|
2142
|
+
match._nonReactive.loaderPromise = undefined
|
|
2143
|
+
|
|
2144
|
+
updateMatch(match.id, (prev) => ({
|
|
2145
|
+
...prev,
|
|
2146
|
+
status: isRedirect(err)
|
|
2147
|
+
? 'redirected'
|
|
2148
|
+
: isNotFound(err)
|
|
2149
|
+
? 'notFound'
|
|
2150
|
+
: 'error',
|
|
2151
|
+
isFetching: false,
|
|
2152
|
+
error: err,
|
|
2153
|
+
}))
|
|
2147
2154
|
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2155
|
+
if (!(err as any).routeId) {
|
|
2156
|
+
;(err as any).routeId = match.routeId
|
|
2157
|
+
}
|
|
2151
2158
|
|
|
2152
|
-
|
|
2159
|
+
match._nonReactive.loadPromise?.resolve()
|
|
2160
|
+
}
|
|
2153
2161
|
|
|
2154
2162
|
if (isRedirect(err)) {
|
|
2155
2163
|
rendered = true
|
|
@@ -2202,13 +2210,13 @@ export class RouterCore<
|
|
|
2202
2210
|
|
|
2203
2211
|
err.routerCode = routerCode
|
|
2204
2212
|
firstBadMatchIndex = firstBadMatchIndex ?? index
|
|
2205
|
-
handleRedirectAndNotFound(this.getMatch(matchId)
|
|
2213
|
+
handleRedirectAndNotFound(this.getMatch(matchId), err)
|
|
2206
2214
|
|
|
2207
2215
|
try {
|
|
2208
2216
|
route.options.onError?.(err)
|
|
2209
2217
|
} catch (errorHandlerErr) {
|
|
2210
2218
|
err = errorHandlerErr
|
|
2211
|
-
handleRedirectAndNotFound(this.getMatch(matchId)
|
|
2219
|
+
handleRedirectAndNotFound(this.getMatch(matchId), err)
|
|
2212
2220
|
}
|
|
2213
2221
|
|
|
2214
2222
|
updateMatch(matchId, (prev) => {
|
|
@@ -2463,35 +2471,45 @@ export class RouterCore<
|
|
|
2463
2471
|
let loaderIsRunningAsync = false
|
|
2464
2472
|
const route = this.looseRoutesById[routeId]!
|
|
2465
2473
|
|
|
2466
|
-
const executeHead =
|
|
2474
|
+
const executeHead = () => {
|
|
2467
2475
|
const match = this.getMatch(matchId)
|
|
2468
2476
|
// in case of a redirecting match during preload, the match does not exist
|
|
2469
2477
|
if (!match) {
|
|
2470
2478
|
return
|
|
2471
2479
|
}
|
|
2480
|
+
if (
|
|
2481
|
+
!route.options.head &&
|
|
2482
|
+
!route.options.scripts &&
|
|
2483
|
+
!route.options.headers
|
|
2484
|
+
) {
|
|
2485
|
+
return
|
|
2486
|
+
}
|
|
2472
2487
|
const assetContext = {
|
|
2473
2488
|
matches,
|
|
2474
2489
|
match,
|
|
2475
2490
|
params: match.params,
|
|
2476
2491
|
loaderData: match.loaderData,
|
|
2477
2492
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2493
|
+
|
|
2494
|
+
return Promise.all([
|
|
2495
|
+
route.options.head?.(assetContext),
|
|
2496
|
+
route.options.scripts?.(assetContext),
|
|
2497
|
+
route.options.headers?.(assetContext),
|
|
2498
|
+
]).then(([headFnContent, scripts, headers]) => {
|
|
2499
|
+
const meta = headFnContent?.meta
|
|
2500
|
+
const links = headFnContent?.links
|
|
2501
|
+
const headScripts = headFnContent?.scripts
|
|
2502
|
+
const styles = headFnContent?.styles
|
|
2503
|
+
|
|
2504
|
+
return {
|
|
2505
|
+
meta,
|
|
2506
|
+
links,
|
|
2507
|
+
headScripts,
|
|
2508
|
+
headers,
|
|
2509
|
+
scripts,
|
|
2510
|
+
styles,
|
|
2511
|
+
}
|
|
2512
|
+
})
|
|
2495
2513
|
}
|
|
2496
2514
|
|
|
2497
2515
|
const potentialPendingMinPromise = async () => {
|
|
@@ -2504,11 +2522,14 @@ export class RouterCore<
|
|
|
2504
2522
|
const prevMatch = this.getMatch(matchId)!
|
|
2505
2523
|
if (shouldSkipLoader(matchId)) {
|
|
2506
2524
|
if (this.isServer) {
|
|
2507
|
-
const
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2525
|
+
const headResult = executeHead()
|
|
2526
|
+
if (headResult) {
|
|
2527
|
+
const head = await headResult
|
|
2528
|
+
updateMatch(matchId, (prev) => ({
|
|
2529
|
+
...prev,
|
|
2530
|
+
...head,
|
|
2531
|
+
}))
|
|
2532
|
+
}
|
|
2512
2533
|
return this.getMatch(matchId)!
|
|
2513
2534
|
}
|
|
2514
2535
|
}
|
|
@@ -2620,7 +2641,7 @@ export class RouterCore<
|
|
|
2620
2641
|
await route.options.loader?.(getLoaderContext())
|
|
2621
2642
|
|
|
2622
2643
|
handleRedirectAndNotFound(
|
|
2623
|
-
this.getMatch(matchId)
|
|
2644
|
+
this.getMatch(matchId),
|
|
2624
2645
|
loaderData,
|
|
2625
2646
|
)
|
|
2626
2647
|
updateMatch(matchId, (prev) => ({
|
|
@@ -2632,7 +2653,8 @@ export class RouterCore<
|
|
|
2632
2653
|
// so we need to wait for it to resolve before
|
|
2633
2654
|
// we can use the options
|
|
2634
2655
|
await route._lazyPromise
|
|
2635
|
-
const
|
|
2656
|
+
const headResult = executeHead()
|
|
2657
|
+
const head = headResult ? await headResult : undefined
|
|
2636
2658
|
await potentialPendingMinPromise()
|
|
2637
2659
|
|
|
2638
2660
|
// Last but not least, wait for the the components
|
|
@@ -2651,18 +2673,19 @@ export class RouterCore<
|
|
|
2651
2673
|
|
|
2652
2674
|
await potentialPendingMinPromise()
|
|
2653
2675
|
|
|
2654
|
-
handleRedirectAndNotFound(this.getMatch(matchId)
|
|
2676
|
+
handleRedirectAndNotFound(this.getMatch(matchId), e)
|
|
2655
2677
|
|
|
2656
2678
|
try {
|
|
2657
2679
|
route.options.onError?.(e)
|
|
2658
2680
|
} catch (onErrorError) {
|
|
2659
2681
|
error = onErrorError
|
|
2660
2682
|
handleRedirectAndNotFound(
|
|
2661
|
-
this.getMatch(matchId)
|
|
2683
|
+
this.getMatch(matchId),
|
|
2662
2684
|
onErrorError,
|
|
2663
2685
|
)
|
|
2664
2686
|
}
|
|
2665
|
-
const
|
|
2687
|
+
const headResult = executeHead()
|
|
2688
|
+
const head = headResult ? await headResult : undefined
|
|
2666
2689
|
updateMatch(matchId, (prev) => ({
|
|
2667
2690
|
...prev,
|
|
2668
2691
|
error,
|
|
@@ -2672,16 +2695,20 @@ export class RouterCore<
|
|
|
2672
2695
|
}))
|
|
2673
2696
|
}
|
|
2674
2697
|
} catch (err) {
|
|
2675
|
-
const
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2698
|
+
const match = this.getMatch(matchId)
|
|
2699
|
+
// in case of a redirecting match during preload, the match does not exist
|
|
2700
|
+
if (match) {
|
|
2701
|
+
const headResult = executeHead()
|
|
2702
|
+
if (headResult) {
|
|
2703
|
+
const head = await headResult
|
|
2704
|
+
updateMatch(matchId, (prev) => ({
|
|
2705
|
+
...prev,
|
|
2706
|
+
...head,
|
|
2707
|
+
}))
|
|
2682
2708
|
}
|
|
2683
|
-
|
|
2684
|
-
|
|
2709
|
+
match._nonReactive.loaderPromise = undefined
|
|
2710
|
+
}
|
|
2711
|
+
handleRedirectAndNotFound(match, err)
|
|
2685
2712
|
}
|
|
2686
2713
|
}
|
|
2687
2714
|
|
|
@@ -2716,11 +2743,14 @@ export class RouterCore<
|
|
|
2716
2743
|
// if the loader did not run, still update head.
|
|
2717
2744
|
// reason: parent's beforeLoad may have changed the route context
|
|
2718
2745
|
// and only now do we know the route context (and that the loader would not run)
|
|
2719
|
-
const
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2746
|
+
const headResult = executeHead()
|
|
2747
|
+
if (headResult) {
|
|
2748
|
+
const head = await headResult
|
|
2749
|
+
updateMatch(matchId, (prev) => ({
|
|
2750
|
+
...prev,
|
|
2751
|
+
...head,
|
|
2752
|
+
}))
|
|
2753
|
+
}
|
|
2724
2754
|
}
|
|
2725
2755
|
}
|
|
2726
2756
|
if (!loaderIsRunningAsync) {
|