@tanstack/react-router 1.91.1 → 1.91.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/link.cjs +7 -5
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/router.cjs +28 -17
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/link.js +7 -5
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.js +28 -17
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/link.tsx +8 -6
- package/src/router.ts +34 -20
package/package.json
CHANGED
package/src/link.tsx
CHANGED
|
@@ -641,10 +641,12 @@ export function useLinkProps<
|
|
|
641
641
|
() => router.buildLocation(options as any),
|
|
642
642
|
[router, options, currentSearch],
|
|
643
643
|
)
|
|
644
|
-
const preload = React.useMemo(
|
|
645
|
-
()
|
|
646
|
-
|
|
647
|
-
|
|
644
|
+
const preload = React.useMemo(() => {
|
|
645
|
+
if (options.reloadDocument) {
|
|
646
|
+
return false
|
|
647
|
+
}
|
|
648
|
+
return userPreload ?? router.options.defaultPreload
|
|
649
|
+
}, [router.options.defaultPreload, userPreload, options.reloadDocument])
|
|
648
650
|
const preloadDelay =
|
|
649
651
|
userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0
|
|
650
652
|
|
|
@@ -768,7 +770,7 @@ export function useLinkProps<
|
|
|
768
770
|
|
|
769
771
|
// All is well? Navigate!
|
|
770
772
|
// N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing
|
|
771
|
-
router.
|
|
773
|
+
return router.navigate({
|
|
772
774
|
...options,
|
|
773
775
|
replace,
|
|
774
776
|
resetScroll,
|
|
@@ -776,7 +778,7 @@ export function useLinkProps<
|
|
|
776
778
|
startTransition,
|
|
777
779
|
viewTransition,
|
|
778
780
|
ignoreBlocker,
|
|
779
|
-
})
|
|
781
|
+
} as any)
|
|
780
782
|
}
|
|
781
783
|
}
|
|
782
784
|
|
package/src/router.ts
CHANGED
|
@@ -1224,6 +1224,16 @@ export class Router<
|
|
|
1224
1224
|
|
|
1225
1225
|
const matches: Array<AnyRouteMatch> = []
|
|
1226
1226
|
|
|
1227
|
+
const getParentContext = (parentMatch?: AnyRouteMatch) => {
|
|
1228
|
+
const parentMatchId = parentMatch?.id
|
|
1229
|
+
|
|
1230
|
+
const parentContext = !parentMatchId
|
|
1231
|
+
? ((this.options.context as any) ?? {})
|
|
1232
|
+
: (parentMatch.context ?? this.options.context ?? {})
|
|
1233
|
+
|
|
1234
|
+
return parentContext
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1227
1237
|
matchedRoutes.forEach((route, index) => {
|
|
1228
1238
|
// Take each matched route and resolve + validate its search params
|
|
1229
1239
|
// This has to happen serially because each route's search params
|
|
@@ -1361,17 +1371,6 @@ export class Router<
|
|
|
1361
1371
|
}
|
|
1362
1372
|
}
|
|
1363
1373
|
|
|
1364
|
-
const headFnContent = route.options.head?.({
|
|
1365
|
-
matches,
|
|
1366
|
-
match,
|
|
1367
|
-
params: match.params,
|
|
1368
|
-
loaderData: match.loaderData ?? undefined,
|
|
1369
|
-
})
|
|
1370
|
-
|
|
1371
|
-
match.links = headFnContent?.links
|
|
1372
|
-
match.scripts = headFnContent?.scripts
|
|
1373
|
-
match.meta = headFnContent?.meta
|
|
1374
|
-
|
|
1375
1374
|
// If it's already a success, update the headers
|
|
1376
1375
|
// These may get updated again if the match is refreshed
|
|
1377
1376
|
// due to being stale
|
|
@@ -1389,11 +1388,7 @@ export class Router<
|
|
|
1389
1388
|
// update the searchError if there is one
|
|
1390
1389
|
match.searchError = searchError
|
|
1391
1390
|
|
|
1392
|
-
const
|
|
1393
|
-
|
|
1394
|
-
const parentContext = !parentMatchId
|
|
1395
|
-
? ((this.options.context as any) ?? {})
|
|
1396
|
-
: (parentMatch.context ?? this.options.context ?? {})
|
|
1391
|
+
const parentContext = getParentContext(parentMatch)
|
|
1397
1392
|
|
|
1398
1393
|
match.context = {
|
|
1399
1394
|
...parentContext,
|
|
@@ -1401,13 +1396,23 @@ export class Router<
|
|
|
1401
1396
|
...match.__beforeLoadContext,
|
|
1402
1397
|
}
|
|
1403
1398
|
|
|
1399
|
+
matches.push(match)
|
|
1400
|
+
})
|
|
1401
|
+
|
|
1402
|
+
matches.forEach((match, index) => {
|
|
1403
|
+
const route = this.looseRoutesById[match.routeId]!
|
|
1404
|
+
const existingMatch = this.getMatch(match.id)
|
|
1405
|
+
|
|
1404
1406
|
// only execute `context` if we are not just building a location
|
|
1405
1407
|
if (!existingMatch && opts?._buildLocation !== true) {
|
|
1408
|
+
const parentMatch = matches[index - 1]
|
|
1409
|
+
const parentContext = getParentContext(parentMatch)
|
|
1410
|
+
|
|
1406
1411
|
// Update the match's context
|
|
1407
1412
|
const contextFnContext: RouteContextOptions<any, any, any, any> = {
|
|
1408
|
-
deps: loaderDeps,
|
|
1413
|
+
deps: match.loaderDeps,
|
|
1409
1414
|
params: match.params,
|
|
1410
|
-
context:
|
|
1415
|
+
context: parentContext,
|
|
1411
1416
|
location: next,
|
|
1412
1417
|
navigate: (opts: any) =>
|
|
1413
1418
|
this.navigate({ ...opts, _fromLocation: next }),
|
|
@@ -1428,10 +1433,19 @@ export class Router<
|
|
|
1428
1433
|
}
|
|
1429
1434
|
}
|
|
1430
1435
|
|
|
1431
|
-
|
|
1436
|
+
const headFnContent = route.options.head?.({
|
|
1437
|
+
matches,
|
|
1438
|
+
match,
|
|
1439
|
+
params: match.params,
|
|
1440
|
+
loaderData: match.loaderData ?? undefined,
|
|
1441
|
+
})
|
|
1442
|
+
|
|
1443
|
+
match.links = headFnContent?.links
|
|
1444
|
+
match.scripts = headFnContent?.scripts
|
|
1445
|
+
match.meta = headFnContent?.meta
|
|
1432
1446
|
})
|
|
1433
1447
|
|
|
1434
|
-
return matches
|
|
1448
|
+
return matches
|
|
1435
1449
|
}
|
|
1436
1450
|
|
|
1437
1451
|
getMatchedRoutes = (next: ParsedLocation, dest?: BuildNextOptions) => {
|