@tanstack/router-core 1.128.4 → 1.128.6

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/src/router.ts CHANGED
@@ -14,6 +14,10 @@ import {
14
14
  replaceEqualDeep,
15
15
  } from './utils'
16
16
  import {
17
+ SEGMENT_TYPE_OPTIONAL_PARAM,
18
+ SEGMENT_TYPE_PARAM,
19
+ SEGMENT_TYPE_PATHNAME,
20
+ SEGMENT_TYPE_WILDCARD,
17
21
  cleanPath,
18
22
  interpolatePath,
19
23
  joinPaths,
@@ -3246,7 +3250,7 @@ export function processRouteTree<TRouteLike extends RouteLike>({
3246
3250
  const scoredRoutes: Array<{
3247
3251
  child: TRouteLike
3248
3252
  trimmed: string
3249
- parsed: Array<Segment>
3253
+ parsed: ReadonlyArray<Segment>
3250
3254
  index: number
3251
3255
  scores: Array<number>
3252
3256
  hasStaticAfter: boolean
@@ -3261,12 +3265,14 @@ export function processRouteTree<TRouteLike extends RouteLike>({
3261
3265
  }
3262
3266
 
3263
3267
  const trimmed = trimPathLeft(d.fullPath)
3264
- const parsed = parsePathname(trimmed)
3268
+ let parsed = parsePathname(trimmed)
3265
3269
 
3266
3270
  // Removes the leading slash if it is not the only remaining segment
3267
- while (parsed.length > 1 && parsed[0]?.value === '/') {
3268
- parsed.shift()
3271
+ let skip = 0
3272
+ while (parsed.length > skip + 1 && parsed[skip]?.value === '/') {
3273
+ skip++
3269
3274
  }
3275
+ if (skip > 0) parsed = parsed.slice(skip)
3270
3276
 
3271
3277
  let optionalParamCount = 0
3272
3278
  let hasStaticAfter = false
@@ -3276,12 +3282,12 @@ export function processRouteTree<TRouteLike extends RouteLike>({
3276
3282
  }
3277
3283
 
3278
3284
  let baseScore: number | undefined = undefined
3279
- if (segment.type === 'param') {
3285
+ if (segment.type === SEGMENT_TYPE_PARAM) {
3280
3286
  baseScore = REQUIRED_PARAM_BASE_SCORE
3281
- } else if (segment.type === 'optional-param') {
3287
+ } else if (segment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
3282
3288
  baseScore = OPTIONAL_PARAM_BASE_SCORE
3283
3289
  optionalParamCount++
3284
- } else if (segment.type === 'wildcard') {
3290
+ } else if (segment.type === SEGMENT_TYPE_WILDCARD) {
3285
3291
  baseScore = WILDCARD_PARAM_BASE_SCORE
3286
3292
  }
3287
3293
 
@@ -3291,7 +3297,10 @@ export function processRouteTree<TRouteLike extends RouteLike>({
3291
3297
  // JUST FOR SORTING, NOT FOR MATCHING
3292
3298
  for (let i = index + 1; i < parsed.length; i++) {
3293
3299
  const nextSegment = parsed[i]!
3294
- if (nextSegment.type === 'pathname' && nextSegment.value !== '/') {
3300
+ if (
3301
+ nextSegment.type === SEGMENT_TYPE_PATHNAME &&
3302
+ nextSegment.value !== '/'
3303
+ ) {
3295
3304
  hasStaticAfter = true
3296
3305
  return handleParam(segment, baseScore + 0.2)
3297
3306
  }
@@ -3412,8 +3421,9 @@ export function getMatchedRoutes<TRouteLike extends RouteLike>({
3412
3421
 
3413
3422
  while (routeCursor.parentRoute) {
3414
3423
  routeCursor = routeCursor.parentRoute as TRouteLike
3415
- matchedRoutes.unshift(routeCursor)
3424
+ matchedRoutes.push(routeCursor)
3416
3425
  }
3426
+ matchedRoutes.reverse()
3417
3427
 
3418
3428
  return { matchedRoutes, routeParams, foundRoute }
3419
3429
  }