@tanstack/router-core 1.108.0 → 1.111.3
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/RouterProvider.d.cts +9 -1
- package/dist/cjs/fileRoute.d.cts +12 -0
- package/dist/cjs/index.d.cts +6 -4
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +80 -5
- package/dist/cjs/route.d.cts +71 -6
- package/dist/cjs/routeInfo.d.cts +54 -0
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +15 -0
- package/dist/esm/RouterProvider.d.ts +9 -1
- package/dist/esm/fileRoute.d.ts +12 -0
- package/dist/esm/index.d.ts +6 -4
- package/dist/esm/link.d.ts +80 -5
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +71 -6
- package/dist/esm/routeInfo.d.ts +54 -0
- package/dist/esm/router.d.ts +15 -0
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/RouterProvider.ts +31 -1
- package/src/fileRoute.ts +32 -0
- package/src/index.ts +70 -1
- package/src/link.ts +445 -37
- package/src/route.ts +250 -28
- package/src/routeInfo.ts +235 -0
- package/src/router.ts +32 -0
package/src/route.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { ParsePathParams } from './link'
|
|
2
2
|
import type { RootRouteId } from './root'
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParseRoute } from './routeInfo'
|
|
4
|
+
import type { RegisteredRouter } from './router'
|
|
5
|
+
import type { Assign, Expand, IntersectAssign } from './utils'
|
|
4
6
|
import type {
|
|
5
7
|
AnySchema,
|
|
6
8
|
AnyStandardSchemaValidator,
|
|
7
9
|
AnyValidatorAdapter,
|
|
8
10
|
AnyValidatorObj,
|
|
11
|
+
ResolveSearchValidatorInput,
|
|
12
|
+
ResolveValidatorOutput,
|
|
9
13
|
StandardSchemaValidator,
|
|
10
14
|
ValidatorAdapter,
|
|
11
15
|
ValidatorFn,
|
|
@@ -213,6 +217,38 @@ export type DefaultSearchValidator = SearchValidator<
|
|
|
213
217
|
AnySchema
|
|
214
218
|
>
|
|
215
219
|
|
|
220
|
+
export type RoutePrefix<
|
|
221
|
+
TPrefix extends string,
|
|
222
|
+
TPath extends string,
|
|
223
|
+
> = string extends TPath
|
|
224
|
+
? RootRouteId
|
|
225
|
+
: TPath extends string
|
|
226
|
+
? TPrefix extends RootRouteId
|
|
227
|
+
? TPath extends '/'
|
|
228
|
+
? '/'
|
|
229
|
+
: `/${TrimPath<TPath>}`
|
|
230
|
+
: `${TPrefix}/${TPath}` extends '/'
|
|
231
|
+
? '/'
|
|
232
|
+
: `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
|
|
233
|
+
: never
|
|
234
|
+
|
|
235
|
+
export type TrimPath<T extends string> = '' extends T
|
|
236
|
+
? ''
|
|
237
|
+
: TrimPathRight<TrimPathLeft<T>>
|
|
238
|
+
|
|
239
|
+
export type TrimPathLeft<T extends string> =
|
|
240
|
+
T extends `${RootRouteId}/${infer U}`
|
|
241
|
+
? TrimPathLeft<U>
|
|
242
|
+
: T extends `/${infer U}`
|
|
243
|
+
? TrimPathLeft<U>
|
|
244
|
+
: T
|
|
245
|
+
|
|
246
|
+
export type TrimPathRight<T extends string> = T extends '/'
|
|
247
|
+
? '/'
|
|
248
|
+
: T extends `${infer U}/`
|
|
249
|
+
? TrimPathRight<U>
|
|
250
|
+
: T
|
|
251
|
+
|
|
216
252
|
export type LooseReturnType<T> = T extends (
|
|
217
253
|
...args: Array<any>
|
|
218
254
|
) => infer TReturn
|
|
@@ -250,36 +286,222 @@ export type ResolveLoaderData<TLoaderFn> = unknown extends TLoaderFn
|
|
|
250
286
|
? undefined
|
|
251
287
|
: LooseAsyncReturnType<TLoaderFn>
|
|
252
288
|
|
|
253
|
-
export type
|
|
254
|
-
|
|
289
|
+
export type ResolveFullSearchSchema<
|
|
290
|
+
TParentRoute extends AnyRoute,
|
|
291
|
+
TSearchValidator,
|
|
292
|
+
> = unknown extends TParentRoute
|
|
293
|
+
? ResolveValidatorOutput<TSearchValidator>
|
|
294
|
+
: IntersectAssign<
|
|
295
|
+
InferFullSearchSchema<TParentRoute>,
|
|
296
|
+
ResolveValidatorOutput<TSearchValidator>
|
|
297
|
+
>
|
|
298
|
+
|
|
299
|
+
export type ResolveFullSearchSchemaInput<
|
|
300
|
+
TParentRoute extends AnyRoute,
|
|
301
|
+
TSearchValidator,
|
|
302
|
+
> = IntersectAssign<
|
|
303
|
+
InferFullSearchSchemaInput<TParentRoute>,
|
|
304
|
+
ResolveSearchValidatorInput<TSearchValidator>
|
|
305
|
+
>
|
|
306
|
+
|
|
307
|
+
export type ResolveAllParamsFromParent<
|
|
308
|
+
TParentRoute extends AnyRoute,
|
|
309
|
+
TParams,
|
|
310
|
+
> = Assign<InferAllParams<TParentRoute>, TParams>
|
|
311
|
+
|
|
312
|
+
export type RouteContextParameter<
|
|
313
|
+
TParentRoute extends AnyRoute,
|
|
314
|
+
TRouterContext,
|
|
315
|
+
> = unknown extends TParentRoute
|
|
316
|
+
? TRouterContext
|
|
317
|
+
: Assign<TRouterContext, InferAllContext<TParentRoute>>
|
|
318
|
+
|
|
319
|
+
export type BeforeLoadContextParameter<
|
|
320
|
+
TParentRoute extends AnyRoute,
|
|
321
|
+
TRouterContext,
|
|
322
|
+
TRouteContextFn,
|
|
323
|
+
> = Assign<
|
|
324
|
+
RouteContextParameter<TParentRoute, TRouterContext>,
|
|
325
|
+
ContextReturnType<TRouteContextFn>
|
|
326
|
+
>
|
|
327
|
+
|
|
328
|
+
export type ResolveAllContext<
|
|
329
|
+
TParentRoute extends AnyRoute,
|
|
330
|
+
TRouterContext,
|
|
331
|
+
TRouteContextFn,
|
|
332
|
+
TBeforeLoadFn,
|
|
333
|
+
> = Assign<
|
|
334
|
+
BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>,
|
|
335
|
+
ContextAsyncReturnType<TBeforeLoadFn>
|
|
336
|
+
>
|
|
337
|
+
export interface FullSearchSchemaOption<
|
|
338
|
+
in out TParentRoute extends AnyRoute,
|
|
339
|
+
in out TSearchValidator,
|
|
340
|
+
> {
|
|
341
|
+
search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface RemountDepsOptions<
|
|
345
|
+
in out TRouteId,
|
|
346
|
+
in out TFullSearchSchema,
|
|
347
|
+
in out TAllParams,
|
|
348
|
+
in out TLoaderDeps,
|
|
349
|
+
> {
|
|
350
|
+
routeId: TRouteId
|
|
351
|
+
search: TFullSearchSchema
|
|
352
|
+
params: TAllParams
|
|
353
|
+
loaderDeps: TLoaderDeps
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export type MakeRemountDepsOptionsUnion<
|
|
357
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
358
|
+
TRoute extends AnyRoute = ParseRoute<TRouteTree>,
|
|
359
|
+
> = TRoute extends any
|
|
360
|
+
? RemountDepsOptions<
|
|
361
|
+
TRoute['id'],
|
|
362
|
+
TRoute['types']['fullSearchSchema'],
|
|
363
|
+
TRoute['types']['allParams'],
|
|
364
|
+
TRoute['types']['loaderDeps']
|
|
365
|
+
>
|
|
366
|
+
: never
|
|
367
|
+
|
|
368
|
+
export interface RouteTypes<
|
|
369
|
+
in out TParentRoute extends AnyRoute,
|
|
370
|
+
in out TPath extends string,
|
|
371
|
+
in out TFullPath extends string,
|
|
372
|
+
in out TCustomId extends string,
|
|
373
|
+
in out TId extends string,
|
|
374
|
+
in out TSearchValidator,
|
|
375
|
+
in out TParams,
|
|
376
|
+
in out TRouterContext,
|
|
377
|
+
in out TRouteContextFn,
|
|
378
|
+
in out TBeforeLoadFn,
|
|
379
|
+
in out TLoaderDeps,
|
|
380
|
+
in out TLoaderFn,
|
|
381
|
+
in out TChildren,
|
|
382
|
+
in out TFileRouteTypes,
|
|
383
|
+
> {
|
|
384
|
+
parentRoute: TParentRoute
|
|
385
|
+
path: TPath
|
|
386
|
+
to: TrimPathRight<TFullPath>
|
|
387
|
+
fullPath: TFullPath
|
|
388
|
+
customId: TCustomId
|
|
389
|
+
id: TId
|
|
390
|
+
searchSchema: ResolveValidatorOutput<TSearchValidator>
|
|
391
|
+
searchSchemaInput: ResolveSearchValidatorInput<TSearchValidator>
|
|
392
|
+
searchValidator: TSearchValidator
|
|
393
|
+
fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>
|
|
394
|
+
fullSearchSchemaInput: ResolveFullSearchSchemaInput<
|
|
395
|
+
TParentRoute,
|
|
396
|
+
TSearchValidator
|
|
397
|
+
>
|
|
398
|
+
params: TParams
|
|
399
|
+
allParams: ResolveAllParamsFromParent<TParentRoute, TParams>
|
|
400
|
+
routerContext: TRouterContext
|
|
401
|
+
routeContext: ResolveRouteContext<TRouteContextFn, TBeforeLoadFn>
|
|
402
|
+
routeContextFn: TRouteContextFn
|
|
403
|
+
beforeLoadFn: TBeforeLoadFn
|
|
404
|
+
allContext: ResolveAllContext<
|
|
405
|
+
TParentRoute,
|
|
406
|
+
TRouterContext,
|
|
407
|
+
TRouteContextFn,
|
|
408
|
+
TBeforeLoadFn
|
|
409
|
+
>
|
|
410
|
+
children: TChildren
|
|
411
|
+
loaderData: ResolveLoaderData<TLoaderFn>
|
|
412
|
+
loaderDeps: TLoaderDeps
|
|
413
|
+
fileRouteTypes: TFileRouteTypes
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export type ResolveFullPath<
|
|
417
|
+
TParentRoute extends AnyRoute,
|
|
255
418
|
TPath extends string,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
419
|
+
TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,
|
|
420
|
+
> = TPrefixed extends RootRouteId ? '/' : TPrefixed
|
|
421
|
+
|
|
422
|
+
export interface Route<
|
|
423
|
+
in out TParentRoute extends AnyRoute,
|
|
424
|
+
in out TPath extends string,
|
|
425
|
+
in out TFullPath extends string,
|
|
426
|
+
in out TCustomId extends string,
|
|
427
|
+
in out TId extends string,
|
|
428
|
+
in out TSearchValidator,
|
|
429
|
+
in out TParams,
|
|
430
|
+
in out TRouterContext,
|
|
431
|
+
in out TRouteContextFn,
|
|
432
|
+
in out TBeforeLoadFn,
|
|
433
|
+
in out TLoaderDeps,
|
|
434
|
+
in out TLoaderFn,
|
|
435
|
+
in out TChildren,
|
|
436
|
+
in out TFileRouteTypes,
|
|
437
|
+
> {
|
|
438
|
+
fullPath: TFullPath
|
|
439
|
+
path: TPath
|
|
440
|
+
id: TId
|
|
441
|
+
types: RouteTypes<
|
|
442
|
+
TParentRoute,
|
|
443
|
+
TPath,
|
|
444
|
+
TFullPath,
|
|
445
|
+
TCustomId,
|
|
446
|
+
TId,
|
|
447
|
+
TSearchValidator,
|
|
448
|
+
TParams,
|
|
449
|
+
TRouterContext,
|
|
450
|
+
TRouteContextFn,
|
|
451
|
+
TBeforeLoadFn,
|
|
452
|
+
TLoaderDeps,
|
|
453
|
+
TLoaderFn,
|
|
454
|
+
TChildren,
|
|
455
|
+
TFileRouteTypes
|
|
456
|
+
>
|
|
457
|
+
}
|
|
267
458
|
|
|
268
|
-
export type
|
|
269
|
-
|
|
270
|
-
|
|
459
|
+
export type AnyRoute = Route<
|
|
460
|
+
any,
|
|
461
|
+
any,
|
|
462
|
+
any,
|
|
463
|
+
any,
|
|
464
|
+
any,
|
|
465
|
+
any,
|
|
466
|
+
any,
|
|
467
|
+
any,
|
|
468
|
+
any,
|
|
469
|
+
any,
|
|
470
|
+
any,
|
|
471
|
+
any,
|
|
472
|
+
any,
|
|
473
|
+
any
|
|
474
|
+
>
|
|
271
475
|
|
|
272
|
-
export
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
476
|
+
export interface RootRoute<
|
|
477
|
+
in out TSearchValidator,
|
|
478
|
+
in out TRouterContext,
|
|
479
|
+
in out TRouteContextFn,
|
|
480
|
+
in out TBeforeLoadFn,
|
|
481
|
+
in out TLoaderDeps extends Record<string, any>,
|
|
482
|
+
in out TLoaderFn,
|
|
483
|
+
in out TChildren,
|
|
484
|
+
in out TFileRouteTypes,
|
|
485
|
+
> extends Route<
|
|
486
|
+
any, // TParentRoute
|
|
487
|
+
'/', // TPath
|
|
488
|
+
'/', // TFullPath
|
|
489
|
+
string, // TCustomId
|
|
490
|
+
RootRouteId, // TId
|
|
491
|
+
TSearchValidator, // TSearchValidator
|
|
492
|
+
{}, // TParams
|
|
493
|
+
TRouterContext,
|
|
494
|
+
TRouteContextFn,
|
|
495
|
+
TBeforeLoadFn,
|
|
496
|
+
TLoaderDeps,
|
|
497
|
+
TLoaderFn,
|
|
498
|
+
TChildren, // TChildren
|
|
499
|
+
TFileRouteTypes
|
|
500
|
+
> {}
|
|
501
|
+
|
|
502
|
+
export type AnyRouteWithContext<TContext> = AnyRoute & {
|
|
503
|
+
types: { allContext: TContext }
|
|
504
|
+
}
|
|
283
505
|
|
|
284
506
|
/**
|
|
285
507
|
* @deprecated Use `ErrorComponentProps` instead.
|
package/src/routeInfo.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { InferFileRouteTypes } from './fileRoute'
|
|
2
|
+
import type { AddTrailingSlash, RemoveTrailingSlashes } from './link'
|
|
3
|
+
import type { AnyRoute } from './route'
|
|
4
|
+
import type { AnyRouter, TrailingSlashOption } from './router'
|
|
5
|
+
import type { PartialMergeAll } from './utils'
|
|
6
|
+
|
|
7
|
+
export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
|
|
8
|
+
types: { children: infer TChildren }
|
|
9
|
+
}
|
|
10
|
+
? unknown extends TChildren
|
|
11
|
+
? TAcc
|
|
12
|
+
: TChildren extends ReadonlyArray<any>
|
|
13
|
+
? ParseRoute<TChildren[number], TAcc | TChildren[number]>
|
|
14
|
+
: ParseRoute<
|
|
15
|
+
TChildren[keyof TChildren],
|
|
16
|
+
TAcc | TChildren[keyof TChildren]
|
|
17
|
+
>
|
|
18
|
+
: TAcc
|
|
19
|
+
|
|
20
|
+
export type ParseRouteWithoutBranches<TRouteTree> =
|
|
21
|
+
ParseRoute<TRouteTree> extends infer TRoute extends AnyRoute
|
|
22
|
+
? TRoute extends any
|
|
23
|
+
? unknown extends TRoute['types']['children']
|
|
24
|
+
? TRoute
|
|
25
|
+
: TRoute['types']['children'] extends ReadonlyArray<any>
|
|
26
|
+
? '/' extends TRoute['types']['children'][number]['path']
|
|
27
|
+
? never
|
|
28
|
+
: TRoute
|
|
29
|
+
: '/' extends TRoute['types']['children'][keyof TRoute['types']['children']]['path']
|
|
30
|
+
? never
|
|
31
|
+
: TRoute
|
|
32
|
+
: never
|
|
33
|
+
: never
|
|
34
|
+
|
|
35
|
+
export type CodeRoutesById<TRouteTree extends AnyRoute> =
|
|
36
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
37
|
+
? {
|
|
38
|
+
[K in TRoutes as K['id']]: K
|
|
39
|
+
}
|
|
40
|
+
: never
|
|
41
|
+
|
|
42
|
+
export type RoutesById<TRouteTree extends AnyRoute> =
|
|
43
|
+
InferFileRouteTypes<TRouteTree> extends never
|
|
44
|
+
? CodeRoutesById<TRouteTree>
|
|
45
|
+
: InferFileRouteTypes<TRouteTree>['fileRoutesById']
|
|
46
|
+
|
|
47
|
+
export type RouteById<TRouteTree extends AnyRoute, TId> = Extract<
|
|
48
|
+
RoutesById<TRouteTree>[TId & keyof RoutesById<TRouteTree>],
|
|
49
|
+
AnyRoute
|
|
50
|
+
>
|
|
51
|
+
|
|
52
|
+
export type CodeRouteIds<TRouteTree extends AnyRoute> =
|
|
53
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
54
|
+
? TRoutes['id']
|
|
55
|
+
: never
|
|
56
|
+
|
|
57
|
+
export type RouteIds<TRouteTree extends AnyRoute> =
|
|
58
|
+
InferFileRouteTypes<TRouteTree> extends never
|
|
59
|
+
? CodeRouteIds<TRouteTree>
|
|
60
|
+
: InferFileRouteTypes<TRouteTree>['id']
|
|
61
|
+
|
|
62
|
+
export type ParentPath<TRouter extends AnyRouter> =
|
|
63
|
+
TrailingSlashOptionByRouter<TRouter> extends 'always'
|
|
64
|
+
? '../'
|
|
65
|
+
: TrailingSlashOptionByRouter<TRouter> extends 'never'
|
|
66
|
+
? '..'
|
|
67
|
+
: '../' | '..'
|
|
68
|
+
|
|
69
|
+
export type CurrentPath<TRouter extends AnyRouter> =
|
|
70
|
+
TrailingSlashOptionByRouter<TRouter> extends 'always'
|
|
71
|
+
? './'
|
|
72
|
+
: TrailingSlashOptionByRouter<TRouter> extends 'never'
|
|
73
|
+
? '.'
|
|
74
|
+
: './' | '.'
|
|
75
|
+
|
|
76
|
+
export type ToPath<TRouter extends AnyRouter, TTo extends string> =
|
|
77
|
+
TrailingSlashOptionByRouter<TRouter> extends 'always'
|
|
78
|
+
? AddTrailingSlash<TTo>
|
|
79
|
+
: TrailingSlashOptionByRouter<TRouter> extends 'never'
|
|
80
|
+
? RemoveTrailingSlashes<TTo>
|
|
81
|
+
: AddTrailingSlash<TTo> | RemoveTrailingSlashes<TTo>
|
|
82
|
+
|
|
83
|
+
export type CatchAllPaths<TRouter extends AnyRouter> =
|
|
84
|
+
| CurrentPath<TRouter>
|
|
85
|
+
| ParentPath<TRouter>
|
|
86
|
+
|
|
87
|
+
export type CodeRoutesByPath<TRouteTree extends AnyRoute> =
|
|
88
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
89
|
+
? {
|
|
90
|
+
[K in TRoutes as K['fullPath']]: K
|
|
91
|
+
}
|
|
92
|
+
: never
|
|
93
|
+
|
|
94
|
+
export type RoutesByPath<TRouteTree extends AnyRoute> =
|
|
95
|
+
InferFileRouteTypes<TRouteTree> extends never
|
|
96
|
+
? CodeRoutesByPath<TRouteTree>
|
|
97
|
+
: InferFileRouteTypes<TRouteTree>['fileRoutesByFullPath']
|
|
98
|
+
|
|
99
|
+
export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<
|
|
100
|
+
RoutesByPath<TRouteTree>[TPath & keyof RoutesByPath<TRouteTree>],
|
|
101
|
+
AnyRoute
|
|
102
|
+
>
|
|
103
|
+
|
|
104
|
+
export type CodeRoutePaths<TRouteTree extends AnyRoute> =
|
|
105
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
106
|
+
? TRoutes['fullPath']
|
|
107
|
+
: never
|
|
108
|
+
|
|
109
|
+
export type RoutePaths<TRouteTree extends AnyRoute> = unknown extends TRouteTree
|
|
110
|
+
? string
|
|
111
|
+
:
|
|
112
|
+
| (InferFileRouteTypes<TRouteTree> extends never
|
|
113
|
+
? CodeRoutePaths<TRouteTree>
|
|
114
|
+
: InferFileRouteTypes<TRouteTree>['fullPaths'])
|
|
115
|
+
| '/'
|
|
116
|
+
|
|
117
|
+
export type RouteToPathAlwaysTrailingSlash<TRoute extends AnyRoute> =
|
|
118
|
+
TRoute['path'] extends '/'
|
|
119
|
+
? TRoute['fullPath']
|
|
120
|
+
: TRoute['fullPath'] extends '/'
|
|
121
|
+
? TRoute['fullPath']
|
|
122
|
+
: `${TRoute['fullPath']}/`
|
|
123
|
+
|
|
124
|
+
export type RouteToPathNeverTrailingSlash<TRoute extends AnyRoute> =
|
|
125
|
+
TRoute['path'] extends '/'
|
|
126
|
+
? TRoute['fullPath'] extends '/'
|
|
127
|
+
? TRoute['fullPath']
|
|
128
|
+
: RemoveTrailingSlashes<TRoute['fullPath']>
|
|
129
|
+
: TRoute['fullPath']
|
|
130
|
+
|
|
131
|
+
export type RouteToPathPreserveTrailingSlash<TRoute extends AnyRoute> =
|
|
132
|
+
| RouteToPathNeverTrailingSlash<TRoute>
|
|
133
|
+
| RouteToPathAlwaysTrailingSlash<TRoute>
|
|
134
|
+
|
|
135
|
+
export type RouteToPathByTrailingSlashOption<TRoute extends AnyRoute> = {
|
|
136
|
+
always: RouteToPathAlwaysTrailingSlash<TRoute>
|
|
137
|
+
preserve: RouteToPathPreserveTrailingSlash<TRoute>
|
|
138
|
+
never: RouteToPathNeverTrailingSlash<TRoute>
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type TrailingSlashOptionByRouter<TRouter extends AnyRouter> =
|
|
142
|
+
TrailingSlashOption extends TRouter['options']['trailingSlash']
|
|
143
|
+
? 'never'
|
|
144
|
+
: NonNullable<TRouter['options']['trailingSlash']>
|
|
145
|
+
|
|
146
|
+
export type RouteToByRouter<
|
|
147
|
+
TRouter extends AnyRouter,
|
|
148
|
+
TRoute extends AnyRoute,
|
|
149
|
+
> = RouteToPathByTrailingSlashOption<TRoute>[TrailingSlashOptionByRouter<TRouter>]
|
|
150
|
+
|
|
151
|
+
export type CodeRouteToPath<TRouter extends AnyRouter> =
|
|
152
|
+
ParseRouteWithoutBranches<TRouter['routeTree']> extends infer TRoute extends
|
|
153
|
+
AnyRoute
|
|
154
|
+
? TRoute extends any
|
|
155
|
+
? RouteToByRouter<TRouter, TRoute>
|
|
156
|
+
: never
|
|
157
|
+
: never
|
|
158
|
+
|
|
159
|
+
export type FileRouteToPath<
|
|
160
|
+
TRouter extends AnyRouter,
|
|
161
|
+
TTo = InferFileRouteTypes<TRouter['routeTree']>['to'],
|
|
162
|
+
TTrailingSlashOption = TrailingSlashOptionByRouter<TRouter>,
|
|
163
|
+
> = 'never' extends TTrailingSlashOption
|
|
164
|
+
? TTo
|
|
165
|
+
: 'always' extends TTrailingSlashOption
|
|
166
|
+
? AddTrailingSlash<TTo>
|
|
167
|
+
: TTo | AddTrailingSlash<TTo>
|
|
168
|
+
|
|
169
|
+
export type RouteToPath<TRouter extends AnyRouter> = unknown extends TRouter
|
|
170
|
+
? string
|
|
171
|
+
: InferFileRouteTypes<TRouter['routeTree']> extends never
|
|
172
|
+
? CodeRouteToPath<TRouter>
|
|
173
|
+
: FileRouteToPath<TRouter>
|
|
174
|
+
|
|
175
|
+
export type CodeRoutesByToPath<TRouter extends AnyRouter> =
|
|
176
|
+
ParseRouteWithoutBranches<TRouter['routeTree']> extends infer TRoutes extends
|
|
177
|
+
AnyRoute
|
|
178
|
+
? {
|
|
179
|
+
[TRoute in TRoutes as RouteToByRouter<TRouter, TRoute>]: TRoute
|
|
180
|
+
}
|
|
181
|
+
: never
|
|
182
|
+
|
|
183
|
+
export type RoutesByToPath<TRouter extends AnyRouter> =
|
|
184
|
+
InferFileRouteTypes<TRouter['routeTree']> extends never
|
|
185
|
+
? CodeRoutesByToPath<TRouter>
|
|
186
|
+
: InferFileRouteTypes<TRouter['routeTree']>['fileRoutesByTo']
|
|
187
|
+
|
|
188
|
+
export type CodeRouteByToPath<TRouter extends AnyRouter, TTo> = Extract<
|
|
189
|
+
RoutesByToPath<TRouter>[TTo & keyof RoutesByToPath<TRouter>],
|
|
190
|
+
AnyRoute
|
|
191
|
+
>
|
|
192
|
+
|
|
193
|
+
export type FileRouteByToPath<TRouter extends AnyRouter, TTo> =
|
|
194
|
+
'never' extends TrailingSlashOptionByRouter<TRouter>
|
|
195
|
+
? CodeRouteByToPath<TRouter, TTo>
|
|
196
|
+
: 'always' extends TrailingSlashOptionByRouter<TRouter>
|
|
197
|
+
? TTo extends '/'
|
|
198
|
+
? CodeRouteByToPath<TRouter, TTo>
|
|
199
|
+
: TTo extends `${infer TPath}/`
|
|
200
|
+
? CodeRouteByToPath<TRouter, TPath>
|
|
201
|
+
: never
|
|
202
|
+
: CodeRouteByToPath<
|
|
203
|
+
TRouter,
|
|
204
|
+
TTo extends '/' ? TTo : RemoveTrailingSlashes<TTo>
|
|
205
|
+
>
|
|
206
|
+
|
|
207
|
+
export type RouteByToPath<TRouter extends AnyRouter, TTo> =
|
|
208
|
+
InferFileRouteTypes<TRouter['routeTree']> extends never
|
|
209
|
+
? CodeRouteByToPath<TRouter, TTo>
|
|
210
|
+
: FileRouteByToPath<TRouter, TTo>
|
|
211
|
+
|
|
212
|
+
export type FullSearchSchema<TRouteTree extends AnyRoute> =
|
|
213
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
214
|
+
? PartialMergeAll<TRoutes['types']['fullSearchSchema']>
|
|
215
|
+
: never
|
|
216
|
+
|
|
217
|
+
export type FullSearchSchemaInput<TRouteTree extends AnyRoute> =
|
|
218
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
219
|
+
? PartialMergeAll<TRoutes['types']['fullSearchSchemaInput']>
|
|
220
|
+
: never
|
|
221
|
+
|
|
222
|
+
export type AllParams<TRouteTree extends AnyRoute> =
|
|
223
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
224
|
+
? PartialMergeAll<TRoutes['types']['allParams']>
|
|
225
|
+
: never
|
|
226
|
+
|
|
227
|
+
export type AllContext<TRouteTree extends AnyRoute> =
|
|
228
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
229
|
+
? PartialMergeAll<TRoutes['types']['allContext']>
|
|
230
|
+
: never
|
|
231
|
+
|
|
232
|
+
export type AllLoaderData<TRouteTree extends AnyRoute> =
|
|
233
|
+
ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute
|
|
234
|
+
? PartialMergeAll<TRoutes['types']['loaderData']>
|
|
235
|
+
: never
|
package/src/router.ts
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import type { ParsedLocation } from './location'
|
|
2
2
|
import type { DeferredPromiseState } from './defer'
|
|
3
3
|
import type { ControlledPromise } from './utils'
|
|
4
|
+
import type { AnyRoute, AnyRouteWithContext } from './route'
|
|
5
|
+
|
|
6
|
+
export interface Register {
|
|
7
|
+
// router: Router
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type RegisteredRouter = Register extends {
|
|
11
|
+
router: infer TRouter extends AnyRouter
|
|
12
|
+
}
|
|
13
|
+
? TRouter
|
|
14
|
+
: AnyRouter
|
|
15
|
+
|
|
16
|
+
export interface RouterOptions<
|
|
17
|
+
in out TTrailingSlashOption extends TrailingSlashOption,
|
|
18
|
+
> {
|
|
19
|
+
trailingSlash?: TTrailingSlashOption
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Router<
|
|
23
|
+
in out TRouteTree extends AnyRoute,
|
|
24
|
+
in out TTrailingSlashOption extends TrailingSlashOption,
|
|
25
|
+
> {
|
|
26
|
+
routeTree: TRouteTree
|
|
27
|
+
options: RouterOptions<TTrailingSlashOption>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type AnyRouterWithContext<TContext> = Router<
|
|
31
|
+
AnyRouteWithContext<TContext>,
|
|
32
|
+
any
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
export type AnyRouter = Router<any, any>
|
|
4
36
|
|
|
5
37
|
export interface ViewTransitionOptions {
|
|
6
38
|
types: Array<string>
|