@tanstack/router-core 1.131.39 → 1.131.41
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/process-route-tree.cjs +17 -11
- package/dist/cjs/process-route-tree.cjs.map +1 -1
- package/dist/cjs/router.cjs +4 -5
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/process-route-tree.js +18 -12
- package/dist/esm/process-route-tree.js.map +1 -1
- package/dist/esm/router.js +4 -5
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/process-route-tree.ts +24 -19
- package/src/router.ts +10 -12
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
SEGMENT_TYPE_OPTIONAL_PARAM,
|
|
4
4
|
SEGMENT_TYPE_PARAM,
|
|
5
5
|
SEGMENT_TYPE_PATHNAME,
|
|
6
|
-
SEGMENT_TYPE_WILDCARD,
|
|
7
6
|
parsePathname,
|
|
8
7
|
trimPathLeft,
|
|
9
8
|
trimPathRight,
|
|
@@ -11,9 +10,12 @@ import {
|
|
|
11
10
|
import type { Segment } from './path'
|
|
12
11
|
import type { RouteLike } from './route'
|
|
13
12
|
|
|
13
|
+
const SLASH_SCORE = 0.75
|
|
14
|
+
const STATIC_SEGMENT_SCORE = 1
|
|
14
15
|
const REQUIRED_PARAM_BASE_SCORE = 0.5
|
|
15
16
|
const OPTIONAL_PARAM_BASE_SCORE = 0.4
|
|
16
17
|
const WILDCARD_PARAM_BASE_SCORE = 0.25
|
|
18
|
+
const STATIC_AFTER_DYNAMIC_BONUS_SCORE = 0.2
|
|
17
19
|
const BOTH_PRESENCE_BASE_SCORE = 0.05
|
|
18
20
|
const PREFIX_PRESENCE_BASE_SCORE = 0.02
|
|
19
21
|
const SUFFIX_PRESENCE_BASE_SCORE = 0.01
|
|
@@ -81,7 +83,11 @@ function sortRoutes<TRouteLike extends RouteLike>(
|
|
|
81
83
|
let hasStaticAfter = false
|
|
82
84
|
const scores = parsed.map((segment, index) => {
|
|
83
85
|
if (segment.value === '/') {
|
|
84
|
-
return
|
|
86
|
+
return SLASH_SCORE
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (segment.type === SEGMENT_TYPE_PATHNAME) {
|
|
90
|
+
return STATIC_SEGMENT_SCORE
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
let baseScore: number | undefined = undefined
|
|
@@ -90,29 +96,28 @@ function sortRoutes<TRouteLike extends RouteLike>(
|
|
|
90
96
|
} else if (segment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
91
97
|
baseScore = OPTIONAL_PARAM_BASE_SCORE
|
|
92
98
|
optionalParamCount++
|
|
93
|
-
} else
|
|
99
|
+
} else {
|
|
94
100
|
baseScore = WILDCARD_PARAM_BASE_SCORE
|
|
95
101
|
}
|
|
96
102
|
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
// if there is any static segment (that is not an index) after a required / optional param,
|
|
104
|
+
// we will boost this param so it ranks higher than a required/optional param without a static segment after it
|
|
105
|
+
// JUST FOR SORTING, NOT FOR MATCHING
|
|
106
|
+
for (let i = index + 1; i < parsed.length; i++) {
|
|
107
|
+
const nextSegment = parsed[i]!
|
|
108
|
+
if (
|
|
109
|
+
nextSegment.type === SEGMENT_TYPE_PATHNAME &&
|
|
110
|
+
nextSegment.value !== '/'
|
|
111
|
+
) {
|
|
112
|
+
hasStaticAfter = true
|
|
113
|
+
return handleParam(
|
|
114
|
+
segment,
|
|
115
|
+
baseScore + STATIC_AFTER_DYNAMIC_BONUS_SCORE,
|
|
116
|
+
)
|
|
110
117
|
}
|
|
111
|
-
|
|
112
|
-
return handleParam(segment, baseScore)
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
return
|
|
120
|
+
return handleParam(segment, baseScore)
|
|
116
121
|
})
|
|
117
122
|
|
|
118
123
|
scoredRoutes.push({
|
package/src/router.ts
CHANGED
|
@@ -1178,27 +1178,26 @@ export class RouterCore<
|
|
|
1178
1178
|
|
|
1179
1179
|
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : ''
|
|
1180
1180
|
|
|
1181
|
-
const { interpolatedPath } = interpolatePath({
|
|
1181
|
+
const { interpolatedPath, usedParams } = interpolatePath({
|
|
1182
1182
|
path: route.fullPath,
|
|
1183
1183
|
params: routeParams,
|
|
1184
1184
|
decodeCharMap: this.pathParamsDecodeCharMap,
|
|
1185
1185
|
})
|
|
1186
1186
|
|
|
1187
|
-
const interpolatePathResult = interpolatePath({
|
|
1188
|
-
path: route.id,
|
|
1189
|
-
params: routeParams,
|
|
1190
|
-
leaveWildcards: true,
|
|
1191
|
-
decodeCharMap: this.pathParamsDecodeCharMap,
|
|
1192
|
-
parseCache: this.parsePathnameCache,
|
|
1193
|
-
})
|
|
1194
|
-
|
|
1195
1187
|
// Waste not, want not. If we already have a match for this route,
|
|
1196
1188
|
// reuse it. This is important for layout routes, which might stick
|
|
1197
1189
|
// around between navigation actions that only change leaf routes.
|
|
1198
1190
|
|
|
1199
1191
|
// Existing matches are matches that are already loaded along with
|
|
1200
1192
|
// pending matches that are still loading
|
|
1201
|
-
const matchId =
|
|
1193
|
+
const matchId =
|
|
1194
|
+
interpolatePath({
|
|
1195
|
+
path: route.id,
|
|
1196
|
+
params: routeParams,
|
|
1197
|
+
leaveWildcards: true,
|
|
1198
|
+
decodeCharMap: this.pathParamsDecodeCharMap,
|
|
1199
|
+
parseCache: this.parsePathnameCache,
|
|
1200
|
+
}).interpolatedPath + loaderDepsHash
|
|
1202
1201
|
|
|
1203
1202
|
const existingMatch = this.getMatch(matchId)
|
|
1204
1203
|
|
|
@@ -1206,8 +1205,7 @@ export class RouterCore<
|
|
|
1206
1205
|
(d) => d.routeId === route.id,
|
|
1207
1206
|
)
|
|
1208
1207
|
|
|
1209
|
-
const strictParams =
|
|
1210
|
-
existingMatch?._strictParams ?? interpolatePathResult.usedParams
|
|
1208
|
+
const strictParams = existingMatch?._strictParams ?? usedParams
|
|
1211
1209
|
|
|
1212
1210
|
let paramsError: PathParamError | undefined = undefined
|
|
1213
1211
|
|