@tanstack/react-router 0.0.1-beta.278 → 0.0.1-beta.279

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.278",
4
+ "version": "0.0.1-beta.279",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.278"
47
+ "@tanstack/history": "0.0.1-beta.279"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/router.ts CHANGED
@@ -347,7 +347,7 @@ export class Router<
347
347
  trimmed: string
348
348
  parsed: ReturnType<typeof parsePathname>
349
349
  index: number
350
- score: number[]
350
+ scores: number[]
351
351
  }[] = []
352
352
 
353
353
  ;(Object.values(this.routesById) as AnyRoute[]).forEach((d, i) => {
@@ -362,7 +362,11 @@ export class Router<
362
362
  parsed.shift()
363
363
  }
364
364
 
365
- const score = parsed.map((d) => {
365
+ const scores = parsed.map((d) => {
366
+ if (d.value === '/') {
367
+ return 0.75
368
+ }
369
+
366
370
  if (d.type === 'param') {
367
371
  return 0.5
368
372
  }
@@ -374,41 +378,32 @@ export class Router<
374
378
  return 1
375
379
  })
376
380
 
377
- scoredRoutes.push({ child: d, trimmed, parsed, index: i, score })
381
+ scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores })
378
382
  })
379
383
 
380
384
  this.flatRoutes = scoredRoutes
381
385
  .sort((a, b) => {
382
- let isIndex = a.trimmed === '/' ? 1 : b.trimmed === '/' ? -1 : 0
383
-
384
- if (isIndex !== 0) return isIndex
385
-
386
- const length = Math.min(a.score.length, b.score.length)
387
-
388
- // Sort by length of score
389
- if (a.score.length !== b.score.length) {
390
- return b.score.length - a.score.length
391
- }
386
+ const minLength = Math.min(a.scores.length, b.scores.length)
392
387
 
393
388
  // Sort by min available score
394
- for (let i = 0; i < length; i++) {
395
- if (a.score[i] !== b.score[i]) {
396
- return b.score[i]! - a.score[i]!
389
+ for (let i = 0; i < minLength; i++) {
390
+ if (a.scores[i] !== b.scores[i]) {
391
+ return b.scores[i]! - a.scores[i]!
397
392
  }
398
393
  }
399
394
 
395
+ // Sort by length of score
396
+ if (a.scores.length !== b.scores.length) {
397
+ return b.scores.length - a.scores.length
398
+ }
399
+
400
400
  // Sort by min available parsed value
401
- for (let i = 0; i < length; i++) {
401
+ for (let i = 0; i < minLength; i++) {
402
402
  if (a.parsed[i]!.value !== b.parsed[i]!.value) {
403
403
  return a.parsed[i]!.value! > b.parsed[i]!.value! ? 1 : -1
404
404
  }
405
405
  }
406
406
 
407
- // Sort by length of trimmed full path
408
- if (a.trimmed !== b.trimmed) {
409
- return a.trimmed > b.trimmed ? 1 : -1
410
- }
411
-
412
407
  // Sort by original index
413
408
  return a.index - b.index
414
409
  })