@tanstack/router-core 1.145.7 → 1.146.0
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/load-matches.cjs +8 -0
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/new-process-route-tree.cjs +137 -33
- package/dist/cjs/new-process-route-tree.cjs.map +1 -1
- package/dist/cjs/new-process-route-tree.d.cts +50 -6
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +39 -0
- package/dist/cjs/router.cjs +33 -23
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +5 -0
- package/dist/esm/load-matches.js +8 -0
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/new-process-route-tree.d.ts +50 -6
- package/dist/esm/new-process-route-tree.js +137 -33
- package/dist/esm/new-process-route-tree.js.map +1 -1
- package/dist/esm/route.d.ts +39 -0
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +5 -0
- package/dist/esm/router.js +33 -23
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/load-matches.ts +9 -0
- package/src/new-process-route-tree.ts +250 -49
- package/src/route.ts +39 -2
- package/src/router.ts +39 -25
package/src/router.ts
CHANGED
|
@@ -698,8 +698,12 @@ export type ParseLocationFn<TRouteTree extends AnyRoute> = (
|
|
|
698
698
|
|
|
699
699
|
export type GetMatchRoutesFn = (pathname: string) => {
|
|
700
700
|
matchedRoutes: ReadonlyArray<AnyRoute>
|
|
701
|
+
/** exhaustive params, still in their string form */
|
|
701
702
|
routeParams: Record<string, string>
|
|
703
|
+
/** partial params, parsed from routeParams during matching */
|
|
704
|
+
parsedParams: Record<string, unknown> | undefined
|
|
702
705
|
foundRoute: AnyRoute | undefined
|
|
706
|
+
parseError?: unknown
|
|
703
707
|
}
|
|
704
708
|
|
|
705
709
|
export type EmitFn = (routerEvent: RouterEvent) => void
|
|
@@ -1260,7 +1264,7 @@ export class RouterCore<
|
|
|
1260
1264
|
opts?: MatchRoutesOpts,
|
|
1261
1265
|
): Array<AnyRouteMatch> {
|
|
1262
1266
|
const matchedRoutesResult = this.getMatchedRoutes(next.pathname)
|
|
1263
|
-
const { foundRoute, routeParams } = matchedRoutesResult
|
|
1267
|
+
const { foundRoute, routeParams, parsedParams } = matchedRoutesResult
|
|
1264
1268
|
let { matchedRoutes } = matchedRoutesResult
|
|
1265
1269
|
let isGlobalNotFound = false
|
|
1266
1270
|
|
|
@@ -1401,26 +1405,34 @@ export class RouterCore<
|
|
|
1401
1405
|
let paramsError: unknown = undefined
|
|
1402
1406
|
|
|
1403
1407
|
if (!existingMatch) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
try {
|
|
1409
|
-
Object.assign(
|
|
1410
|
-
strictParams,
|
|
1411
|
-
strictParseParams(strictParams as Record<string, string>),
|
|
1412
|
-
)
|
|
1413
|
-
} catch (err: any) {
|
|
1414
|
-
if (isNotFound(err) || isRedirect(err)) {
|
|
1415
|
-
paramsError = err
|
|
1416
|
-
} else {
|
|
1417
|
-
paramsError = new PathParamError(err.message, {
|
|
1418
|
-
cause: err,
|
|
1419
|
-
})
|
|
1408
|
+
if (route.options.skipRouteOnParseError) {
|
|
1409
|
+
for (const key in usedParams) {
|
|
1410
|
+
if (key in parsedParams!) {
|
|
1411
|
+
strictParams[key] = parsedParams![key]
|
|
1420
1412
|
}
|
|
1413
|
+
}
|
|
1414
|
+
} else {
|
|
1415
|
+
const strictParseParams =
|
|
1416
|
+
route.options.params?.parse ?? route.options.parseParams
|
|
1421
1417
|
|
|
1422
|
-
|
|
1423
|
-
|
|
1418
|
+
if (strictParseParams) {
|
|
1419
|
+
try {
|
|
1420
|
+
Object.assign(
|
|
1421
|
+
strictParams,
|
|
1422
|
+
strictParseParams(strictParams as Record<string, string>),
|
|
1423
|
+
)
|
|
1424
|
+
} catch (err: any) {
|
|
1425
|
+
if (isNotFound(err) || isRedirect(err)) {
|
|
1426
|
+
paramsError = err
|
|
1427
|
+
} else {
|
|
1428
|
+
paramsError = new PathParamError(err.message, {
|
|
1429
|
+
cause: err,
|
|
1430
|
+
})
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
if (opts?.throwOnError) {
|
|
1434
|
+
throw paramsError
|
|
1435
|
+
}
|
|
1424
1436
|
}
|
|
1425
1437
|
}
|
|
1426
1438
|
}
|
|
@@ -1802,7 +1814,7 @@ export class RouterCore<
|
|
|
1802
1814
|
this.processedTree,
|
|
1803
1815
|
)
|
|
1804
1816
|
if (match) {
|
|
1805
|
-
Object.assign(params, match.
|
|
1817
|
+
Object.assign(params, match.rawParams) // Copy params, because they're cached
|
|
1806
1818
|
const {
|
|
1807
1819
|
from: _from,
|
|
1808
1820
|
params: maskParams,
|
|
@@ -2601,18 +2613,18 @@ export class RouterCore<
|
|
|
2601
2613
|
}
|
|
2602
2614
|
|
|
2603
2615
|
if (location.params) {
|
|
2604
|
-
if (!deepEqual(match.
|
|
2616
|
+
if (!deepEqual(match.rawParams, location.params, { partial: true })) {
|
|
2605
2617
|
return false
|
|
2606
2618
|
}
|
|
2607
2619
|
}
|
|
2608
2620
|
|
|
2609
2621
|
if (opts?.includeSearch ?? true) {
|
|
2610
2622
|
return deepEqual(baseLocation.search, next.search, { partial: true })
|
|
2611
|
-
? match.
|
|
2623
|
+
? match.rawParams
|
|
2612
2624
|
: false
|
|
2613
2625
|
}
|
|
2614
2626
|
|
|
2615
|
-
return match.
|
|
2627
|
+
return match.rawParams
|
|
2616
2628
|
}
|
|
2617
2629
|
|
|
2618
2630
|
ssr?: {
|
|
@@ -2719,15 +2731,17 @@ export function getMatchedRoutes<TRouteLike extends RouteLike>({
|
|
|
2719
2731
|
const trimmedPath = trimPathRight(pathname)
|
|
2720
2732
|
|
|
2721
2733
|
let foundRoute: TRouteLike | undefined = undefined
|
|
2734
|
+
let parsedParams: Record<string, unknown> | undefined = undefined
|
|
2722
2735
|
const match = findRouteMatch<TRouteLike>(trimmedPath, processedTree, true)
|
|
2723
2736
|
if (match) {
|
|
2724
2737
|
foundRoute = match.route
|
|
2725
|
-
Object.assign(routeParams, match.
|
|
2738
|
+
Object.assign(routeParams, match.rawParams) // Copy params, because they're cached
|
|
2739
|
+
parsedParams = Object.assign({}, match.parsedParams)
|
|
2726
2740
|
}
|
|
2727
2741
|
|
|
2728
2742
|
const matchedRoutes = match?.branch || [routesById[rootRouteId]!]
|
|
2729
2743
|
|
|
2730
|
-
return { matchedRoutes, routeParams, foundRoute }
|
|
2744
|
+
return { matchedRoutes, routeParams, foundRoute, parsedParams }
|
|
2731
2745
|
}
|
|
2732
2746
|
|
|
2733
2747
|
function applySearchMiddleware({
|