@tanstack/react-router 1.49.8 → 1.50.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.
- package/dist/cjs/Matches.cjs +10 -0
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +34 -5
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -2
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +13 -13
- package/dist/cjs/router.cjs +2 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/Matches.d.ts +34 -5
- package/dist/esm/Matches.js +10 -0
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +2 -2
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/route.d.ts +13 -13
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.js +2 -1
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +121 -5
- package/src/fileRoute.ts +2 -0
- package/src/index.tsx +1 -0
- package/src/route.ts +16 -1
- package/src/router.ts +1 -0
package/package.json
CHANGED
package/src/Matches.tsx
CHANGED
|
@@ -25,10 +25,109 @@ import type {
|
|
|
25
25
|
RouteIds,
|
|
26
26
|
RoutePaths,
|
|
27
27
|
} from './routeInfo'
|
|
28
|
-
import type {
|
|
28
|
+
import type {
|
|
29
|
+
Constrain,
|
|
30
|
+
ControlledPromise,
|
|
31
|
+
DeepPartial,
|
|
32
|
+
NoInfer,
|
|
33
|
+
} from './utils'
|
|
34
|
+
|
|
35
|
+
export type AnyMatchAndValue = { match: any; value: any }
|
|
36
|
+
|
|
37
|
+
export type FindValueByIndex<
|
|
38
|
+
TKey,
|
|
39
|
+
TValue extends ReadonlyArray<any>,
|
|
40
|
+
> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never
|
|
41
|
+
|
|
42
|
+
export type FindValueByKey<TKey, TValue> =
|
|
43
|
+
TValue extends ReadonlyArray<any>
|
|
44
|
+
? FindValueByIndex<TKey, TValue>
|
|
45
|
+
: TValue[TKey & keyof TValue]
|
|
46
|
+
|
|
47
|
+
export type CreateMatchAndValue<TMatch, TValue> = TValue extends any
|
|
48
|
+
? {
|
|
49
|
+
match: TMatch
|
|
50
|
+
value: TValue
|
|
51
|
+
}
|
|
52
|
+
: never
|
|
53
|
+
|
|
54
|
+
export type NextMatchAndValue<
|
|
55
|
+
TKey,
|
|
56
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
57
|
+
> = TMatchAndValue extends any
|
|
58
|
+
? CreateMatchAndValue<
|
|
59
|
+
TMatchAndValue['match'],
|
|
60
|
+
FindValueByKey<TKey, TMatchAndValue['value']>
|
|
61
|
+
>
|
|
62
|
+
: never
|
|
63
|
+
|
|
64
|
+
export type IsMatchKeyOf<TValue> =
|
|
65
|
+
TValue extends ReadonlyArray<any>
|
|
66
|
+
? number extends TValue['length']
|
|
67
|
+
? `${number}`
|
|
68
|
+
: keyof TValue & `${number}`
|
|
69
|
+
: TValue extends object
|
|
70
|
+
? keyof TValue & string
|
|
71
|
+
: never
|
|
72
|
+
|
|
73
|
+
export type IsMatchPath<
|
|
74
|
+
TParentPath extends string,
|
|
75
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
76
|
+
> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`
|
|
77
|
+
|
|
78
|
+
export type IsMatchResult<
|
|
79
|
+
TKey,
|
|
80
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
81
|
+
> = TMatchAndValue extends any
|
|
82
|
+
? TKey extends keyof TMatchAndValue['value']
|
|
83
|
+
? TMatchAndValue['match']
|
|
84
|
+
: never
|
|
85
|
+
: never
|
|
86
|
+
|
|
87
|
+
export type IsMatchParse<
|
|
88
|
+
TPath,
|
|
89
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
90
|
+
TParentPath extends string = '',
|
|
91
|
+
> = TPath extends `${string}.${string}`
|
|
92
|
+
? TPath extends `${infer TFirst}.${infer TRest}`
|
|
93
|
+
? IsMatchParse<
|
|
94
|
+
TRest,
|
|
95
|
+
NextMatchAndValue<TFirst, TMatchAndValue>,
|
|
96
|
+
`${TParentPath}${TFirst}.`
|
|
97
|
+
>
|
|
98
|
+
: never
|
|
99
|
+
: {
|
|
100
|
+
path: IsMatchPath<TParentPath, TMatchAndValue>
|
|
101
|
+
result: IsMatchResult<TPath, TMatchAndValue>
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type IsMatch<TMatch, TPath> = IsMatchParse<
|
|
105
|
+
TPath,
|
|
106
|
+
TMatch extends any ? { match: TMatch; value: TMatch } : never
|
|
107
|
+
>
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Narrows matches based on a path
|
|
111
|
+
* @experimental
|
|
112
|
+
*/
|
|
113
|
+
export const isMatch = <TMatch, TPath extends string>(
|
|
114
|
+
match: TMatch,
|
|
115
|
+
path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,
|
|
116
|
+
): match is IsMatch<TMatch, TPath>['result'] => {
|
|
117
|
+
const parts = (path as string).split('.')
|
|
118
|
+
let part
|
|
119
|
+
let value: any = match
|
|
120
|
+
|
|
121
|
+
while ((part = parts.shift()) != null && value != null) {
|
|
122
|
+
value = value[part]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return value != null
|
|
126
|
+
}
|
|
29
127
|
|
|
30
128
|
export interface RouteMatch<
|
|
31
129
|
TRouteId,
|
|
130
|
+
TFullPath,
|
|
32
131
|
TAllParams,
|
|
33
132
|
TFullSearchSchema,
|
|
34
133
|
TLoaderData,
|
|
@@ -37,6 +136,7 @@ export interface RouteMatch<
|
|
|
37
136
|
> {
|
|
38
137
|
id: string
|
|
39
138
|
routeId: TRouteId
|
|
139
|
+
fullPath: TFullPath
|
|
40
140
|
index: number
|
|
41
141
|
pathname: string
|
|
42
142
|
params: TAllParams
|
|
@@ -76,6 +176,7 @@ export type MakeRouteMatch<
|
|
|
76
176
|
TRouteId = ParseRoute<TRouteTree>['id'],
|
|
77
177
|
TStrict extends boolean = true,
|
|
78
178
|
TTypes extends AnyRoute['types'] = RouteById<TRouteTree, TRouteId>['types'],
|
|
179
|
+
TFullPath = TTypes['fullPath'],
|
|
79
180
|
TAllParams = TStrict extends false
|
|
80
181
|
? AllParams<TRouteTree>
|
|
81
182
|
: TTypes['allParams'],
|
|
@@ -91,6 +192,7 @@ export type MakeRouteMatch<
|
|
|
91
192
|
TLoaderDeps = TTypes['loaderDeps'],
|
|
92
193
|
> = RouteMatch<
|
|
93
194
|
TRouteId,
|
|
195
|
+
TFullPath,
|
|
94
196
|
TAllParams,
|
|
95
197
|
TFullSearchSchema,
|
|
96
198
|
TLoaderData,
|
|
@@ -98,7 +200,7 @@ export type MakeRouteMatch<
|
|
|
98
200
|
TLoaderDeps
|
|
99
201
|
>
|
|
100
202
|
|
|
101
|
-
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any>
|
|
203
|
+
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>
|
|
102
204
|
|
|
103
205
|
export function Matches() {
|
|
104
206
|
const router = useRouter()
|
|
@@ -254,10 +356,24 @@ export function MatchRoute<
|
|
|
254
356
|
return params ? props.children : null
|
|
255
357
|
}
|
|
256
358
|
|
|
359
|
+
export type MakeRouteMatches<
|
|
360
|
+
TRouter extends AnyRouter = AnyRouter,
|
|
361
|
+
TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,
|
|
362
|
+
> = TRoute extends any
|
|
363
|
+
? RouteMatch<
|
|
364
|
+
TRoute['id'],
|
|
365
|
+
TRoute['fullPath'],
|
|
366
|
+
TRoute['types']['allParams'],
|
|
367
|
+
TRoute['types']['fullSearchSchema'],
|
|
368
|
+
TRoute['types']['loaderData'],
|
|
369
|
+
TRoute['types']['allContext'],
|
|
370
|
+
TRoute['types']['loaderDeps']
|
|
371
|
+
>
|
|
372
|
+
: never
|
|
373
|
+
|
|
257
374
|
export function useMatches<
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,
|
|
375
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
376
|
+
TRouteMatch = MakeRouteMatches<TRouter>,
|
|
261
377
|
T = Array<TRouteMatch>,
|
|
262
378
|
>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {
|
|
263
379
|
return useRouterState({
|
package/src/fileRoute.ts
CHANGED
|
@@ -88,6 +88,7 @@ export class FileRoute<
|
|
|
88
88
|
UpdatableRouteOptions<
|
|
89
89
|
TParentRoute,
|
|
90
90
|
TId,
|
|
91
|
+
TFullPath,
|
|
91
92
|
TParams,
|
|
92
93
|
TSearchValidator,
|
|
93
94
|
TLoaderFn,
|
|
@@ -155,6 +156,7 @@ export type LazyRouteOptions = Pick<
|
|
|
155
156
|
UpdatableRouteOptions<
|
|
156
157
|
AnyRoute,
|
|
157
158
|
string,
|
|
159
|
+
string,
|
|
158
160
|
AnyPathParams,
|
|
159
161
|
AnySearchValidator,
|
|
160
162
|
{},
|
package/src/index.tsx
CHANGED
package/src/route.ts
CHANGED
|
@@ -53,6 +53,7 @@ export type RoutePathOptionsIntersection<TCustomId, TPath> = {
|
|
|
53
53
|
export type RouteOptions<
|
|
54
54
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
55
55
|
TCustomId extends string = string,
|
|
56
|
+
TFullPath extends string = string,
|
|
56
57
|
TPath extends string = string,
|
|
57
58
|
TSearchValidator = undefined,
|
|
58
59
|
TParams = AnyPathParams,
|
|
@@ -76,6 +77,7 @@ export type RouteOptions<
|
|
|
76
77
|
UpdatableRouteOptions<
|
|
77
78
|
NoInfer<TParentRoute>,
|
|
78
79
|
NoInfer<TCustomId>,
|
|
80
|
+
NoInfer<TFullPath>,
|
|
79
81
|
NoInfer<TParams>,
|
|
80
82
|
NoInfer<TSearchValidator>,
|
|
81
83
|
NoInfer<TLoaderFn>,
|
|
@@ -309,6 +311,7 @@ export interface BeforeLoadContextOptions<
|
|
|
309
311
|
export interface UpdatableRouteOptions<
|
|
310
312
|
in out TParentRoute extends AnyRoute,
|
|
311
313
|
in out TRouteId,
|
|
314
|
+
in out TFullPath,
|
|
312
315
|
in out TParams,
|
|
313
316
|
in out TSearchValidator,
|
|
314
317
|
in out TLoaderFn,
|
|
@@ -351,6 +354,7 @@ export interface UpdatableRouteOptions<
|
|
|
351
354
|
onEnter?: (
|
|
352
355
|
match: RouteMatch<
|
|
353
356
|
TRouteId,
|
|
357
|
+
TFullPath,
|
|
354
358
|
ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
355
359
|
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
|
|
356
360
|
ResolveLoaderData<TLoaderFn>,
|
|
@@ -366,6 +370,7 @@ export interface UpdatableRouteOptions<
|
|
|
366
370
|
onStay?: (
|
|
367
371
|
match: RouteMatch<
|
|
368
372
|
TRouteId,
|
|
373
|
+
TFullPath,
|
|
369
374
|
ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
370
375
|
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
|
|
371
376
|
ResolveLoaderData<TLoaderFn>,
|
|
@@ -381,6 +386,7 @@ export interface UpdatableRouteOptions<
|
|
|
381
386
|
onLeave?: (
|
|
382
387
|
match: RouteMatch<
|
|
383
388
|
TRouteId,
|
|
389
|
+
TFullPath,
|
|
384
390
|
ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
385
391
|
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
|
|
386
392
|
ResolveLoaderData<TLoaderFn>,
|
|
@@ -397,6 +403,7 @@ export interface UpdatableRouteOptions<
|
|
|
397
403
|
matches: Array<
|
|
398
404
|
RouteMatch<
|
|
399
405
|
TRouteId,
|
|
406
|
+
TFullPath,
|
|
400
407
|
ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
401
408
|
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
|
|
402
409
|
ResolveLoaderData<TLoaderFn>,
|
|
@@ -411,6 +418,7 @@ export interface UpdatableRouteOptions<
|
|
|
411
418
|
>
|
|
412
419
|
match: RouteMatch<
|
|
413
420
|
TRouteId,
|
|
421
|
+
TFullPath,
|
|
414
422
|
ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
415
423
|
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
|
|
416
424
|
ResolveLoaderData<TLoaderFn>,
|
|
@@ -860,6 +868,7 @@ export class Route<
|
|
|
860
868
|
options: RouteOptions<
|
|
861
869
|
TParentRoute,
|
|
862
870
|
TCustomId,
|
|
871
|
+
TFullPath,
|
|
863
872
|
TPath,
|
|
864
873
|
TSearchValidator,
|
|
865
874
|
TParams,
|
|
@@ -893,6 +902,7 @@ export class Route<
|
|
|
893
902
|
options?: RouteOptions<
|
|
894
903
|
TParentRoute,
|
|
895
904
|
TCustomId,
|
|
905
|
+
TFullPath,
|
|
896
906
|
TPath,
|
|
897
907
|
TSearchValidator,
|
|
898
908
|
TParams,
|
|
@@ -952,6 +962,7 @@ export class Route<
|
|
|
952
962
|
| (RouteOptions<
|
|
953
963
|
TParentRoute,
|
|
954
964
|
TCustomId,
|
|
965
|
+
TFullPath,
|
|
955
966
|
TPath,
|
|
956
967
|
TSearchValidator,
|
|
957
968
|
TParams,
|
|
@@ -1075,6 +1086,7 @@ export class Route<
|
|
|
1075
1086
|
options: UpdatableRouteOptions<
|
|
1076
1087
|
TParentRoute,
|
|
1077
1088
|
TCustomId,
|
|
1089
|
+
TFullPath,
|
|
1078
1090
|
TParams,
|
|
1079
1091
|
TSearchValidator,
|
|
1080
1092
|
TLoaderFn,
|
|
@@ -1193,6 +1205,7 @@ export function createRoute<
|
|
|
1193
1205
|
options: RouteOptions<
|
|
1194
1206
|
TParentRoute,
|
|
1195
1207
|
TCustomId,
|
|
1208
|
+
TFullPath,
|
|
1196
1209
|
TPath,
|
|
1197
1210
|
TSearchValidator,
|
|
1198
1211
|
TParams,
|
|
@@ -1232,7 +1245,8 @@ export type RootRouteOptions<
|
|
|
1232
1245
|
> = Omit<
|
|
1233
1246
|
RouteOptions<
|
|
1234
1247
|
any, // TParentRoute
|
|
1235
|
-
RootRouteId,
|
|
1248
|
+
RootRouteId,
|
|
1249
|
+
'', // TCustomId
|
|
1236
1250
|
'', // TPath
|
|
1237
1251
|
TSearchValidator,
|
|
1238
1252
|
{}, // TParams
|
|
@@ -1495,6 +1509,7 @@ export class NotFoundRoute<
|
|
|
1495
1509
|
TParentRoute,
|
|
1496
1510
|
string,
|
|
1497
1511
|
string,
|
|
1512
|
+
string,
|
|
1498
1513
|
TSearchValidator,
|
|
1499
1514
|
{},
|
|
1500
1515
|
TLoaderDeps,
|