@tanstack/react-router 0.0.1-beta.277 → 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/build/cjs/Matches.js +7 -3
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/router.js +17 -21
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +24 -24
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +353 -353
- package/build/umd/index.development.js +24 -24
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +6 -3
- package/src/router.ts +19 -24
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.
|
|
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.
|
|
47
|
+
"@tanstack/history": "0.0.1-beta.279"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -95,6 +95,8 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
95
95
|
const PendingComponent = (route.options.pendingComponent ??
|
|
96
96
|
router.options.defaultPendingComponent) as any
|
|
97
97
|
|
|
98
|
+
const pendingElement = PendingComponent ? <PendingComponent /> : null
|
|
99
|
+
|
|
98
100
|
const routeErrorComponent =
|
|
99
101
|
route.options.errorComponent ??
|
|
100
102
|
router.options.defaultErrorComponent ??
|
|
@@ -115,7 +117,7 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
115
117
|
|
|
116
118
|
return (
|
|
117
119
|
<matchContext.Provider value={matchId}>
|
|
118
|
-
<ResolvedSuspenseBoundary fallback={
|
|
120
|
+
<ResolvedSuspenseBoundary fallback={pendingElement}>
|
|
119
121
|
<ResolvedCatchBoundary
|
|
120
122
|
getResetKey={() => router.state.resolvedLocation.state?.key}
|
|
121
123
|
errorComponent={routeErrorComponent}
|
|
@@ -123,7 +125,7 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
123
125
|
warning(false, `Error in route match: ${matchId}`)
|
|
124
126
|
}}
|
|
125
127
|
>
|
|
126
|
-
<MatchInner matchId={matchId!} pendingElement={
|
|
128
|
+
<MatchInner matchId={matchId!} pendingElement={pendingElement} />
|
|
127
129
|
</ResolvedCatchBoundary>
|
|
128
130
|
</ResolvedSuspenseBoundary>
|
|
129
131
|
</matchContext.Provider>
|
|
@@ -161,7 +163,7 @@ function MatchInner({
|
|
|
161
163
|
|
|
162
164
|
if (match.status === 'pending') {
|
|
163
165
|
if (match.showPending) {
|
|
164
|
-
return pendingElement
|
|
166
|
+
return pendingElement
|
|
165
167
|
}
|
|
166
168
|
throw match.loadPromise
|
|
167
169
|
}
|
|
@@ -218,6 +220,7 @@ export type UseMatchRouteOptions<
|
|
|
218
220
|
export function useMatchRoute<
|
|
219
221
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
220
222
|
>() {
|
|
223
|
+
useRouterState({ select: (s) => [s.location, s.resolvedLocation] })
|
|
221
224
|
const { matchRoute } = useRouter()
|
|
222
225
|
|
|
223
226
|
return React.useCallback(
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
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 <
|
|
395
|
-
if (a.
|
|
396
|
-
return b.
|
|
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 <
|
|
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
|
})
|
|
@@ -989,11 +984,11 @@ export class Router<
|
|
|
989
984
|
let firstBadMatchIndex: number | undefined
|
|
990
985
|
|
|
991
986
|
const updateMatch = (match: AnyRouteMatch) => {
|
|
992
|
-
const isPreload = this.state.preloadMatches.find((d) => d.id === match.id)
|
|
987
|
+
// const isPreload = this.state.preloadMatches.find((d) => d.id === match.id)
|
|
993
988
|
const isPending = this.state.pendingMatches?.find(
|
|
994
989
|
(d) => d.id === match.id,
|
|
995
990
|
)
|
|
996
|
-
const matchesKey =
|
|
991
|
+
const matchesKey = preload
|
|
997
992
|
? 'preloadMatches'
|
|
998
993
|
: isPending
|
|
999
994
|
? 'pendingMatches'
|