-
-
Notifications
You must be signed in to change notification settings - Fork 896
/
Copy pathroute.ts
1273 lines (1180 loc) · 30 KB
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { LazyRoute } from './fileRoute'
import type { NavigateOptions, ParsePathParams } from './link'
import type { ParsedLocation } from './location'
import type {
AnyRouteMatch,
MakeRouteMatchFromRoute,
MakeRouteMatchUnion,
RouteMatch,
} from './Matches'
import type { RootRouteId } from './root'
import type {
FullSearchSchema,
ParseRoute,
RouteById,
RoutePaths,
} from './routeInfo'
import type { AnyRouter, RegisteredRouter } from './router'
import type { BuildLocationFn, NavigateFn } from './RouterProvider'
import type {
Assign,
Constrain,
Expand,
IntersectAssign,
NoInfer,
} from './utils'
import type {
AnySchema,
AnyStandardSchemaValidator,
AnyValidator,
AnyValidatorAdapter,
AnyValidatorObj,
DefaultValidator,
ResolveSearchValidatorInput,
ResolveValidatorOutput,
StandardSchemaValidator,
ValidatorAdapter,
ValidatorFn,
ValidatorObj,
} from './validators'
export type AnyPathParams = {}
export type SearchSchemaInput = {
__TSearchSchemaInput__: 'TSearchSchemaInput'
}
export type AnyContext = {}
export interface RouteContext {}
export type PreloadableObj = { preload?: () => Promise<void> }
export type RoutePathOptions<TCustomId, TPath> =
| {
path: TPath
}
| {
id: TCustomId
}
export interface StaticDataRouteOption {}
export type RoutePathOptionsIntersection<TCustomId, TPath> = {
path: TPath
id: TCustomId
}
export type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult
export type SearchMiddlewareContext<TSearchSchema> = {
search: TSearchSchema
next: (newSearch: TSearchSchema) => TSearchSchema
}
export type SearchMiddleware<TSearchSchema> = (
ctx: SearchMiddlewareContext<TSearchSchema>,
) => TSearchSchema
export type ResolveId<
TParentRoute,
TCustomId extends string,
TPath extends string,
> = TParentRoute extends { id: infer TParentId extends string }
? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>
: RootRouteId
export type InferFullSearchSchema<TRoute> = TRoute extends {
types: {
fullSearchSchema: infer TFullSearchSchema
}
}
? TFullSearchSchema
: {}
export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
types: {
fullSearchSchemaInput: infer TFullSearchSchemaInput
}
}
? TFullSearchSchemaInput
: {}
export type InferAllParams<TRoute> = TRoute extends {
types: {
allParams: infer TAllParams
}
}
? TAllParams
: {}
export type InferAllContext<TRoute> = unknown extends TRoute
? TRoute
: TRoute extends {
types: {
allContext: infer TAllContext
}
}
? TAllContext
: {}
export type ResolveSearchSchemaFnInput<TSearchValidator> =
TSearchValidator extends (input: infer TSearchSchemaInput) => any
? TSearchSchemaInput extends SearchSchemaInput
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
: ResolveSearchSchemaFn<TSearchValidator>
: AnySchema
export type ResolveSearchSchemaInput<TSearchValidator> =
TSearchValidator extends AnyStandardSchemaValidator
? NonNullable<TSearchValidator['~standard']['types']>['input']
: TSearchValidator extends AnyValidatorAdapter
? TSearchValidator['types']['input']
: TSearchValidator extends AnyValidatorObj
? ResolveSearchSchemaFnInput<TSearchValidator['parse']>
: ResolveSearchSchemaFnInput<TSearchValidator>
export type ResolveSearchSchemaFn<TSearchValidator> = TSearchValidator extends (
...args: any
) => infer TSearchSchema
? TSearchSchema
: AnySchema
export type ResolveSearchSchema<TSearchValidator> =
unknown extends TSearchValidator
? TSearchValidator
: TSearchValidator extends AnyStandardSchemaValidator
? NonNullable<TSearchValidator['~standard']['types']>['output']
: TSearchValidator extends AnyValidatorAdapter
? TSearchValidator['types']['output']
: TSearchValidator extends AnyValidatorObj
? ResolveSearchSchemaFn<TSearchValidator['parse']>
: ResolveSearchSchemaFn<TSearchValidator>
export type ParseSplatParams<TPath extends string> = TPath &
`${string}$` extends never
? TPath & `${string}$/${string}` extends never
? never
: '_splat'
: '_splat'
export interface SplatParams {
_splat?: string
}
export type ResolveParams<TPath extends string> =
ParseSplatParams<TPath> extends never
? Record<ParsePathParams<TPath>, string>
: Record<ParsePathParams<TPath>, string> & SplatParams
export type ParseParamsFn<in out TPath extends string, in out TParams> = (
rawParams: ResolveParams<TPath>,
) => TParams extends Record<ParsePathParams<TPath>, any>
? TParams
: Record<ParsePathParams<TPath>, any>
export type StringifyParamsFn<in out TPath extends string, in out TParams> = (
params: TParams,
) => ResolveParams<TPath>
export type ParamsOptions<in out TPath extends string, in out TParams> = {
params?: {
parse?: ParseParamsFn<TPath, TParams>
stringify?: StringifyParamsFn<TPath, TParams>
}
/**
@deprecated Use params.parse instead
*/
parseParams?: ParseParamsFn<TPath, TParams>
/**
@deprecated Use params.stringify instead
*/
stringifyParams?: StringifyParamsFn<TPath, TParams>
}
interface RequiredStaticDataRouteOption {
staticData: StaticDataRouteOption
}
interface OptionalStaticDataRouteOption {
staticData?: StaticDataRouteOption
}
export type UpdatableStaticRouteOption = {} extends StaticDataRouteOption
? OptionalStaticDataRouteOption
: RequiredStaticDataRouteOption
export type MetaDescriptor =
| { charSet: 'utf-8' }
| { title: string }
| { name: string; content: string }
| { property: string; content: string }
| { httpEquiv: string; content: string }
| { 'script:ld+json': LdJsonObject }
| { tagName: 'meta' | 'link'; [name: string]: string }
| Record<string, unknown>
type LdJsonObject = { [Key in string]: LdJsonValue } & {
[Key in string]?: LdJsonValue | undefined
}
type LdJsonArray = Array<LdJsonValue> | ReadonlyArray<LdJsonValue>
type LdJsonPrimitive = string | number | boolean | null
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray
export type RouteLinkEntry = {}
export type SearchValidator<TInput, TOutput> =
| ValidatorObj<TInput, TOutput>
| ValidatorFn<TInput, TOutput>
| ValidatorAdapter<TInput, TOutput>
| StandardSchemaValidator<TInput, TOutput>
| undefined
export type AnySearchValidator = SearchValidator<any, any>
export type DefaultSearchValidator = SearchValidator<
Record<string, unknown>,
AnySchema
>
export type RoutePrefix<
TPrefix extends string,
TPath extends string,
> = string extends TPath
? RootRouteId
: TPath extends string
? TPrefix extends RootRouteId
? TPath extends '/'
? '/'
: `/${TrimPath<TPath>}`
: `${TPrefix}/${TPath}` extends '/'
? '/'
: `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
: never
export type TrimPath<T extends string> = '' extends T
? ''
: TrimPathRight<TrimPathLeft<T>>
export type TrimPathLeft<T extends string> =
T extends `${RootRouteId}/${infer U}`
? TrimPathLeft<U>
: T extends `/${infer U}`
? TrimPathLeft<U>
: T
export type TrimPathRight<T extends string> = T extends '/'
? '/'
: T extends `${infer U}/`
? TrimPathRight<U>
: T
export type LooseReturnType<T> = T extends (
...args: Array<any>
) => infer TReturn
? TReturn
: never
export type LooseAsyncReturnType<T> = T extends (
...args: Array<any>
) => infer TReturn
? TReturn extends Promise<infer TReturn>
? TReturn
: TReturn
: never
export type ContextReturnType<TContextFn> = unknown extends TContextFn
? TContextFn
: LooseReturnType<TContextFn> extends never
? AnyContext
: LooseReturnType<TContextFn>
export type ContextAsyncReturnType<TContextFn> = unknown extends TContextFn
? TContextFn
: LooseAsyncReturnType<TContextFn> extends never
? AnyContext
: LooseAsyncReturnType<TContextFn>
export type ResolveRouteContext<TRouteContextFn, TBeforeLoadFn> = Assign<
ContextReturnType<TRouteContextFn>,
ContextAsyncReturnType<TBeforeLoadFn>
>
export type ResolveLoaderData<TLoaderFn> = unknown extends TLoaderFn
? TLoaderFn
: LooseAsyncReturnType<TLoaderFn> extends never
? undefined
: LooseAsyncReturnType<TLoaderFn>
export type ResolveFullSearchSchema<
TParentRoute extends AnyRoute,
TSearchValidator,
> = unknown extends TParentRoute
? ResolveValidatorOutput<TSearchValidator>
: IntersectAssign<
InferFullSearchSchema<TParentRoute>,
ResolveValidatorOutput<TSearchValidator>
>
export type ResolveFullSearchSchemaInput<
TParentRoute extends AnyRoute,
TSearchValidator,
> = IntersectAssign<
InferFullSearchSchemaInput<TParentRoute>,
ResolveSearchValidatorInput<TSearchValidator>
>
export type ResolveAllParamsFromParent<
TParentRoute extends AnyRoute,
TParams,
> = Assign<InferAllParams<TParentRoute>, TParams>
export type RouteContextParameter<
TParentRoute extends AnyRoute,
TRouterContext,
> = unknown extends TParentRoute
? TRouterContext
: Assign<TRouterContext, InferAllContext<TParentRoute>>
export type BeforeLoadContextParameter<
TParentRoute extends AnyRoute,
TRouterContext,
TRouteContextFn,
> = Assign<
RouteContextParameter<TParentRoute, TRouterContext>,
ContextReturnType<TRouteContextFn>
>
export type ResolveAllContext<
TParentRoute extends AnyRoute,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
> = Assign<
BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>,
ContextAsyncReturnType<TBeforeLoadFn>
>
export interface FullSearchSchemaOption<
in out TParentRoute extends AnyRoute,
in out TSearchValidator,
> {
search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>
}
export interface RemountDepsOptions<
in out TRouteId,
in out TFullSearchSchema,
in out TAllParams,
in out TLoaderDeps,
> {
routeId: TRouteId
search: TFullSearchSchema
params: TAllParams
loaderDeps: TLoaderDeps
}
export type MakeRemountDepsOptionsUnion<
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
> =
ParseRoute<TRouteTree> extends infer TRoute extends AnyRoute
? TRoute extends any
? RemountDepsOptions<
TRoute['id'],
TRoute['types']['fullSearchSchema'],
TRoute['types']['allParams'],
TRoute['types']['loaderDeps']
>
: never
: never
export interface RouteTypes<
in out TParentRoute extends AnyRoute,
in out TPath extends string,
in out TFullPath extends string,
in out TCustomId extends string,
in out TId extends string,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
in out TRouteContextFn,
in out TBeforeLoadFn,
in out TLoaderDeps,
in out TLoaderFn,
in out TChildren,
in out TFileRouteTypes,
> {
parentRoute: TParentRoute
path: TPath
to: TrimPathRight<TFullPath>
fullPath: TFullPath
customId: TCustomId
id: TId
searchSchema: ResolveValidatorOutput<TSearchValidator>
searchSchemaInput: ResolveSearchValidatorInput<TSearchValidator>
searchValidator: TSearchValidator
fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>
fullSearchSchemaInput: ResolveFullSearchSchemaInput<
TParentRoute,
TSearchValidator
>
params: TParams
allParams: ResolveAllParamsFromParent<TParentRoute, TParams>
routerContext: TRouterContext
routeContext: ResolveRouteContext<TRouteContextFn, TBeforeLoadFn>
routeContextFn: TRouteContextFn
beforeLoadFn: TBeforeLoadFn
allContext: ResolveAllContext<
TParentRoute,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>
children: TChildren
loaderData: ResolveLoaderData<TLoaderFn>
loaderDeps: TLoaderDeps
fileRouteTypes: TFileRouteTypes
}
export type ResolveFullPath<
TParentRoute extends AnyRoute,
TPath extends string,
TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,
> = TPrefixed extends RootRouteId ? '/' : TPrefixed
export interface RouteExtensions<TId, TFullPath> {}
export type RouteLazyFn<TRoute extends AnyRoute> = (
lazyFn: () => Promise<LazyRoute>,
) => TRoute
export type RouteAddChildrenFn<
in out TParentRoute extends AnyRoute,
in out TPath extends string,
in out TFullPath extends string,
in out TCustomId extends string,
in out TId extends string,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
in out TRouteContextFn,
in out TBeforeLoadFn,
in out TLoaderDeps extends Record<string, any>,
in out TLoaderFn,
in out TFileRouteTypes,
> = <const TNewChildren>(
children: Constrain<
TNewChildren,
ReadonlyArray<AnyRoute> | Record<string, AnyRoute>
>,
) => Route<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TNewChildren,
TFileRouteTypes
>
export type RouteAddFileChildrenFn<
in out TParentRoute extends AnyRoute,
in out TPath extends string,
in out TFullPath extends string,
in out TCustomId extends string,
in out TId extends string,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
in out TRouteContextFn,
in out TBeforeLoadFn,
in out TLoaderDeps extends Record<string, any>,
in out TLoaderFn,
in out TFileRouteTypes,
> = <const TNewChildren>(
children: TNewChildren,
) => Route<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TNewChildren,
TFileRouteTypes
>
export type RouteAddFileTypesFn<
TParentRoute extends AnyRoute,
TPath extends string,
TFullPath extends string,
TCustomId extends string,
TId extends string,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps extends Record<string, any>,
TLoaderFn,
TChildren,
> = <TNewFileRouteTypes>() => Route<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TChildren,
TNewFileRouteTypes
>
export interface Route<
in out TParentRoute extends AnyRoute,
in out TPath extends string,
in out TFullPath extends string,
in out TCustomId extends string,
in out TId extends string,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
in out TRouteContextFn,
in out TBeforeLoadFn,
in out TLoaderDeps extends Record<string, any>,
in out TLoaderFn,
in out TChildren,
in out TFileRouteTypes,
> extends RouteExtensions<TId, TFullPath> {
fullPath: TFullPath
path: TPath
id: TId
parentRoute: TParentRoute
children?: TChildren
types: RouteTypes<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TChildren,
TFileRouteTypes
>
options: RouteOptions<
TParentRoute,
TId,
TCustomId,
TFullPath,
TPath,
TSearchValidator,
TParams,
TLoaderDeps,
TLoaderFn,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>
isRoot: TParentRoute extends AnyRoute ? true : false
_componentsPromise?: Promise<Array<void>>
lazyFn?: () => Promise<LazyRoute>
_lazyPromise?: Promise<void>
rank: number
to: TrimPathRight<TFullPath>
init: (opts: { originalIndex: number; defaultSsr?: boolean }) => void
update: (
options: UpdatableRouteOptions<
TParentRoute,
TCustomId,
TFullPath,
TParams,
TSearchValidator,
TLoaderFn,
TLoaderDeps,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>,
) => this
lazy: RouteLazyFn<this>
addChildren: RouteAddChildrenFn<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TFileRouteTypes
>
_addFileChildren: RouteAddFileChildrenFn<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TFileRouteTypes
>
_addFileTypes: RouteAddFileTypesFn<
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TChildren
>
}
export type AnyRoute = Route<
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any
>
export type AnyRouteWithContext<TContext> = AnyRoute & {
types: { allContext: TContext }
}
export type RouteOptions<
TParentRoute extends AnyRoute = AnyRoute,
TId extends string = string,
TCustomId extends string = string,
TFullPath extends string = string,
TPath extends string = string,
TSearchValidator = undefined,
TParams = AnyPathParams,
TLoaderDeps extends Record<string, any> = {},
TLoaderFn = undefined,
TRouterContext = {},
TRouteContextFn = AnyContext,
TBeforeLoadFn = AnyContext,
> = BaseRouteOptions<
TParentRoute,
TId,
TCustomId,
TPath,
TSearchValidator,
TParams,
TLoaderDeps,
TLoaderFn,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
> &
UpdatableRouteOptions<
NoInfer<TParentRoute>,
NoInfer<TCustomId>,
NoInfer<TFullPath>,
NoInfer<TParams>,
NoInfer<TSearchValidator>,
NoInfer<TLoaderFn>,
NoInfer<TLoaderDeps>,
NoInfer<TRouterContext>,
NoInfer<TRouteContextFn>,
NoInfer<TBeforeLoadFn>
>
export type RouteContextFn<
in out TParentRoute extends AnyRoute,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
> = (
ctx: RouteContextOptions<
TParentRoute,
TSearchValidator,
TParams,
TRouterContext
>,
) => any
export type BeforeLoadFn<
in out TParentRoute extends AnyRoute,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
in out TRouteContextFn,
> = (
ctx: BeforeLoadContextOptions<
TParentRoute,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn
>,
) => any
export type FileBaseRouteOptions<
TParentRoute extends AnyRoute = AnyRoute,
TId extends string = string,
TPath extends string = string,
TSearchValidator = undefined,
TParams = {},
TLoaderDeps extends Record<string, any> = {},
TLoaderFn = undefined,
TRouterContext = {},
TRouteContextFn = AnyContext,
TBeforeLoadFn = AnyContext,
TRemountDepsFn = AnyContext,
> = ParamsOptions<TPath, TParams> & {
validateSearch?: Constrain<TSearchValidator, AnyValidator, DefaultValidator>
shouldReload?:
| boolean
| ((
match: LoaderFnContext<
TParentRoute,
TId,
TParams,
TLoaderDeps,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>,
) => any)
context?: Constrain<
TRouteContextFn,
(
ctx: RouteContextOptions<
TParentRoute,
TParams,
TRouterContext,
TLoaderDeps
>,
) => any
>
// This async function is called before a route is loaded.
// If an error is thrown here, the route's loader will not be called.
// If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.
// If thrown during a preload event, the error will be logged to the console.
beforeLoad?: Constrain<
TBeforeLoadFn,
(
ctx: BeforeLoadContextOptions<
TParentRoute,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn
>,
) => any
>
loaderDeps?: (
opts: FullSearchSchemaOption<TParentRoute, TSearchValidator>,
) => TLoaderDeps
remountDeps?: Constrain<
TRemountDepsFn,
(
opt: RemountDepsOptions<
TId,
FullSearchSchemaOption<TParentRoute, TSearchValidator>,
Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>,
TLoaderDeps
>,
) => any
>
loader?: Constrain<
TLoaderFn,
(
ctx: LoaderFnContext<
TParentRoute,
TId,
TParams,
TLoaderDeps,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>,
) => any
>
}
export type BaseRouteOptions<
TParentRoute extends AnyRoute = AnyRoute,
TId extends string = string,
TCustomId extends string = string,
TPath extends string = string,
TSearchValidator = undefined,
TParams = {},
TLoaderDeps extends Record<string, any> = {},
TLoaderFn = undefined,
TRouterContext = {},
TRouteContextFn = AnyContext,
TBeforeLoadFn = AnyContext,
> = RoutePathOptions<TCustomId, TPath> &
FileBaseRouteOptions<
TParentRoute,
TId,
TPath,
TSearchValidator,
TParams,
TLoaderDeps,
TLoaderFn,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
> & {
getParentRoute: () => TParentRoute
}
export interface ContextOptions<
in out TParentRoute extends AnyRoute,
in out TParams,
> {
abortController: AbortController
preload: boolean
params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>
location: ParsedLocation
/**
* @deprecated Use `throw redirect({ to: '/somewhere' })` instead
**/
navigate: NavigateFn
buildLocation: BuildLocationFn
cause: 'preload' | 'enter' | 'stay'
matches: Array<MakeRouteMatchUnion>
}
export interface RouteContextOptions<
in out TParentRoute extends AnyRoute,
in out TParams,
in out TRouterContext,
in out TLoaderDeps,
> extends ContextOptions<TParentRoute, TParams> {
deps: TLoaderDeps
context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>
}
export interface BeforeLoadContextOptions<
in out TParentRoute extends AnyRoute,
in out TSearchValidator,
in out TParams,
in out TRouterContext,
in out TRouteContextFn,
> extends ContextOptions<TParentRoute, TParams>,
FullSearchSchemaOption<TParentRoute, TSearchValidator> {
context: Expand<
BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>
>
}
type AssetFnContextOptions<
in out TRouteId,
in out TFullPath,
in out TParentRoute extends AnyRoute,
in out TParams,
in out TSearchValidator,
in out TLoaderFn,
in out TRouterContext,
in out TRouteContextFn,
in out TBeforeLoadFn,
in out TLoaderDeps,
> = {
matches: Array<
RouteMatch<
TRouteId,
TFullPath,
ResolveAllParamsFromParent<TParentRoute, TParams>,
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
ResolveLoaderData<TLoaderFn>,
ResolveAllContext<
TParentRoute,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>,
TLoaderDeps
>
>
match: RouteMatch<
TRouteId,
TFullPath,
ResolveAllParamsFromParent<TParentRoute, TParams>,
ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
ResolveLoaderData<TLoaderFn>,
ResolveAllContext<
TParentRoute,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn
>,
TLoaderDeps
>
params: ResolveAllParamsFromParent<TParentRoute, TParams>
loaderData: ResolveLoaderData<TLoaderFn>
}
export interface DefaultUpdatableRouteOptionsExtensions {
component?: unknown
errorComponent?: unknown
notFoundComponent?: unknown
pendingComponent?: unknown
}
export interface UpdatableRouteOptionsExtensions
extends DefaultUpdatableRouteOptionsExtensions {}
export interface UpdatableRouteOptions<
in out TParentRoute extends AnyRoute,
in out TRouteId,
in out TFullPath,
in out TParams,
in out TSearchValidator,
in out TLoaderFn,
in out TLoaderDeps,
in out TRouterContext,
in out TRouteContextFn,
in out TBeforeLoadFn,
> extends UpdatableStaticRouteOption,
UpdatableRouteOptionsExtensions {
// If true, this route will be matched as case-sensitive
caseSensitive?: boolean
// If true, this route will be forcefully wrapped in a suspense boundary
wrapInSuspense?: boolean
// The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
pendingMs?: number
pendingMinMs?: number
staleTime?: number
gcTime?: number
preload?: boolean
preloadStaleTime?: number