@tanstack/router-core 1.170.0 → 1.171.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.
@@ -403,6 +403,7 @@ function parseSegments<TRouteLike extends RouteLike>(
403
403
  }
404
404
 
405
405
  node.parse = parseParams ?? null
406
+ node.priority = route.options?.params?.priority ?? 0
406
407
 
407
408
  // make node "matchable"
408
409
  if (isLeaf && !node.route) {
@@ -430,16 +431,20 @@ function sortDynamic(
430
431
  suffix?: string
431
432
  caseSensitive: boolean
432
433
  parse: null | ((params: Record<string, string>) => unknown)
434
+ priority: number
433
435
  },
434
436
  b: {
435
437
  prefix?: string
436
438
  suffix?: string
437
439
  caseSensitive: boolean
438
440
  parse: null | ((params: Record<string, string>) => unknown)
441
+ priority: number
439
442
  },
440
443
  ) {
441
444
  if (a.parse && !b.parse) return -1
442
445
  if (!a.parse && b.parse) return 1
446
+ if (a.parse && b.parse && (a.priority || b.priority))
447
+ return b.priority - a.priority
443
448
  if (a.prefix && b.prefix && a.prefix !== b.prefix) {
444
449
  if (a.prefix.startsWith(b.prefix)) return -1
445
450
  if (b.prefix.startsWith(a.prefix)) return 1
@@ -512,6 +517,7 @@ function createStaticNode<T extends RouteLike>(
512
517
  fullPath,
513
518
  parent: null,
514
519
  parse: null,
520
+ priority: 0,
515
521
  }
516
522
  }
517
523
 
@@ -543,6 +549,7 @@ function createDynamicNode<T extends RouteLike>(
543
549
  fullPath,
544
550
  parent: null,
545
551
  parse: null,
552
+ priority: 0,
546
553
  caseSensitive,
547
554
  prefix,
548
555
  suffix,
@@ -605,6 +612,9 @@ type SegmentNode<T extends RouteLike> = {
605
612
 
606
613
  /** route.options.params.parse function, set on the last node of the route */
607
614
  parse: null | ((params: Record<string, string>) => unknown)
615
+
616
+ /** route.options.params.priority ?? 0 */
617
+ priority: number
608
618
  }
609
619
 
610
620
  type RouteLike = {
@@ -618,6 +628,7 @@ type RouteLike = {
618
628
  parseParams?: (params: Record<string, string>) => unknown
619
629
  params?: {
620
630
  parse?: (params: Record<string, string>) => unknown
631
+ priority?: number
621
632
  }
622
633
  }
623
634
  } &
package/src/route.ts CHANGED
@@ -188,6 +188,13 @@ export type StringifyParamsFn<in out TPath extends string, in out TParams> = (
188
188
  export type ParamsOptions<in out TPath extends string, in out TParams> = {
189
189
  params?: {
190
190
  parse?: ParseParamsFn<TPath, TParams> & ValidateParsedParams<TPath, TParams>
191
+ /**
192
+ * When multiple route candidates use `params.parse` during matching,
193
+ * higher priorities are tried first.
194
+ *
195
+ * @default 0
196
+ */
197
+ priority?: number
191
198
  stringify?: StringifyParamsFn<TPath, TParams>
192
199
  }
193
200