@tanstack/react-router 1.31.29 → 1.32.2
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.d.cts +6 -9
- package/dist/cjs/RouterProvider.d.cts +6 -6
- package/dist/cjs/awaited.d.cts +1 -1
- package/dist/cjs/defer.d.cts +1 -0
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +38 -79
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -3
- package/dist/cjs/lazyRouteComponent.d.cts +2 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +56 -50
- package/dist/cjs/location.d.cts +3 -2
- package/dist/cjs/not-found.d.cts +2 -2
- package/dist/cjs/path.d.cts +3 -2
- package/dist/cjs/redirects.d.cts +5 -4
- package/dist/cjs/route.cjs +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +59 -52
- package/dist/cjs/routeInfo.d.cts +12 -11
- package/dist/cjs/router.cjs +2 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +19 -20
- package/dist/cjs/routerContext.d.cts +1 -1
- package/dist/cjs/scroll-restoration.d.cts +2 -1
- package/dist/cjs/searchParams.d.cts +2 -1
- package/dist/cjs/useBlocker.d.cts +3 -2
- package/dist/cjs/useLocation.cjs +10 -0
- package/dist/cjs/useLocation.cjs.map +1 -0
- package/dist/cjs/useLocation.d.cts +5 -0
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +5 -4
- package/dist/cjs/useParams.d.cts +5 -5
- package/dist/cjs/useRouteContext.d.cts +5 -4
- package/dist/cjs/useRouter.d.cts +2 -1
- package/dist/cjs/useRouterState.d.cts +2 -1
- package/dist/cjs/useSearch.d.cts +5 -4
- package/dist/esm/Matches.d.ts +6 -9
- package/dist/esm/RouterProvider.d.ts +6 -6
- package/dist/esm/awaited.d.ts +1 -1
- package/dist/esm/defer.d.ts +1 -0
- package/dist/esm/fileRoute.d.ts +38 -79
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lazyRouteComponent.d.ts +2 -1
- package/dist/esm/link.d.ts +56 -50
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/location.d.ts +3 -2
- package/dist/esm/not-found.d.ts +2 -2
- package/dist/esm/path.d.ts +3 -2
- package/dist/esm/redirects.d.ts +5 -4
- package/dist/esm/route.d.ts +59 -52
- package/dist/esm/route.js +1 -1
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +12 -11
- package/dist/esm/router.d.ts +19 -20
- package/dist/esm/router.js +2 -2
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -1
- package/dist/esm/scroll-restoration.d.ts +2 -1
- package/dist/esm/searchParams.d.ts +2 -1
- package/dist/esm/useBlocker.d.ts +3 -2
- package/dist/esm/useLocation.d.ts +5 -0
- package/dist/esm/useLocation.js +10 -0
- package/dist/esm/useLocation.js.map +1 -0
- package/dist/esm/useNavigate.d.ts +5 -4
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +5 -5
- package/dist/esm/useRouteContext.d.ts +5 -4
- package/dist/esm/useRouter.d.ts +2 -1
- package/dist/esm/useRouterState.d.ts +2 -1
- package/dist/esm/useSearch.d.ts +5 -4
- package/package.json +2 -10
- package/src/fileRoute.ts +26 -104
- package/src/index.tsx +1 -8
- package/src/link.tsx +205 -156
- package/src/route.ts +121 -106
- package/src/routeInfo.ts +24 -22
- package/src/useLocation.tsx +15 -0
- package/src/useNavigate.tsx +2 -2
package/src/route.ts
CHANGED
|
@@ -57,16 +57,16 @@ export type RouteOptions<
|
|
|
57
57
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
58
58
|
TCustomId extends string = string,
|
|
59
59
|
TPath extends string = string,
|
|
60
|
-
TSearchSchemaInput
|
|
61
|
-
TSearchSchema
|
|
60
|
+
TSearchSchemaInput = {},
|
|
61
|
+
TSearchSchema = {},
|
|
62
62
|
TSearchSchemaUsed = {},
|
|
63
63
|
TFullSearchSchemaInput = TSearchSchemaUsed,
|
|
64
64
|
TFullSearchSchema = TSearchSchema,
|
|
65
65
|
TParams = AnyPathParams,
|
|
66
66
|
TAllParams = TParams,
|
|
67
|
-
TRouteContextReturn
|
|
67
|
+
TRouteContextReturn = RouteContext,
|
|
68
68
|
TRouteContext = RouteContext,
|
|
69
|
-
TRouterContext
|
|
69
|
+
TRouterContext = AnyContext,
|
|
70
70
|
TAllContext = AnyContext,
|
|
71
71
|
TLoaderDeps extends Record<string, any> = {},
|
|
72
72
|
TLoaderDataReturn = unknown,
|
|
@@ -109,14 +109,14 @@ export type ParamsFallback<
|
|
|
109
109
|
export type FileBaseRouteOptions<
|
|
110
110
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
111
111
|
TPath extends string = string,
|
|
112
|
-
TSearchSchemaInput
|
|
113
|
-
TSearchSchema
|
|
112
|
+
TSearchSchemaInput = {},
|
|
113
|
+
TSearchSchema = {},
|
|
114
114
|
TFullSearchSchema = TSearchSchema,
|
|
115
115
|
TParams = {},
|
|
116
116
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
117
|
-
TRouteContextReturn
|
|
117
|
+
TRouteContextReturn = RouteContext,
|
|
118
118
|
TRouteContext = RouteContext,
|
|
119
|
-
TRouterContext
|
|
119
|
+
TRouterContext = AnyContext,
|
|
120
120
|
TAllContext = AnyContext,
|
|
121
121
|
TLoaderDeps extends Record<string, any> = {},
|
|
122
122
|
TLoaderDataReturn = unknown,
|
|
@@ -173,16 +173,16 @@ export type BaseRouteOptions<
|
|
|
173
173
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
174
174
|
TCustomId extends string = string,
|
|
175
175
|
TPath extends string = string,
|
|
176
|
-
TSearchSchemaInput
|
|
177
|
-
TSearchSchema
|
|
176
|
+
TSearchSchemaInput = {},
|
|
177
|
+
TSearchSchema = {},
|
|
178
178
|
TSearchSchemaUsed = {},
|
|
179
179
|
TFullSearchSchemaInput = TSearchSchemaUsed,
|
|
180
180
|
TFullSearchSchema = TSearchSchema,
|
|
181
181
|
TParams = {},
|
|
182
182
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
183
|
-
TRouteContextReturn
|
|
183
|
+
TRouteContextReturn = RouteContext,
|
|
184
184
|
TRouteContext = RouteContext,
|
|
185
|
-
TRouterContext
|
|
185
|
+
TRouterContext = AnyContext,
|
|
186
186
|
TAllContext = AnyContext,
|
|
187
187
|
TLoaderDeps extends Record<string, any> = {},
|
|
188
188
|
TLoaderDataReturn = unknown,
|
|
@@ -209,8 +209,8 @@ type BeforeLoadFn<
|
|
|
209
209
|
in out TFullSearchSchema,
|
|
210
210
|
in out TParentRoute extends AnyRoute,
|
|
211
211
|
in out TAllParams,
|
|
212
|
-
TRouteContextReturn
|
|
213
|
-
in out TRouterContext
|
|
212
|
+
TRouteContextReturn,
|
|
213
|
+
in out TRouterContext = AnyContext,
|
|
214
214
|
in out TContext = IsAny<TParentRoute['types']['allContext'], TRouterContext>,
|
|
215
215
|
> = (opts: {
|
|
216
216
|
search: TFullSearchSchema
|
|
@@ -393,25 +393,54 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
|
|
|
393
393
|
? TFullSearchSchemaInput
|
|
394
394
|
: {}
|
|
395
395
|
|
|
396
|
+
export type ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema> =
|
|
397
|
+
TSearchSchemaInput extends SearchSchemaInput
|
|
398
|
+
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
|
|
399
|
+
: TSearchSchema
|
|
400
|
+
|
|
396
401
|
export type ResolveFullSearchSchema<
|
|
397
402
|
TParentRoute extends AnyRoute,
|
|
398
403
|
TSearchSchema,
|
|
399
|
-
> =
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
404
|
+
> = unknown extends TParentRoute
|
|
405
|
+
? Omit<TSearchSchema, keyof RootSearchSchema>
|
|
406
|
+
: Assign<
|
|
407
|
+
TParentRoute['id'] extends RootRouteId
|
|
408
|
+
? Omit<TParentRoute['types']['searchSchema'], keyof RootSearchSchema>
|
|
409
|
+
: TParentRoute['types']['fullSearchSchema'],
|
|
410
|
+
TSearchSchema
|
|
411
|
+
>
|
|
405
412
|
|
|
406
413
|
export type ResolveFullSearchSchemaInput<
|
|
407
414
|
TParentRoute extends AnyRoute,
|
|
408
415
|
TSearchSchemaUsed,
|
|
409
|
-
> =
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
416
|
+
> = unknown extends TParentRoute
|
|
417
|
+
? Omit<TSearchSchemaUsed, keyof RootSearchSchema>
|
|
418
|
+
: Assign<
|
|
419
|
+
TParentRoute['id'] extends RootRouteId
|
|
420
|
+
? Omit<
|
|
421
|
+
TParentRoute['types']['searchSchemaInput'],
|
|
422
|
+
keyof RootSearchSchema
|
|
423
|
+
>
|
|
424
|
+
: TParentRoute['types']['fullSearchSchemaInput'],
|
|
425
|
+
TSearchSchemaUsed
|
|
426
|
+
>
|
|
427
|
+
|
|
428
|
+
export type ResolveRouteContext<TRouteContextReturn> = [
|
|
429
|
+
TRouteContextReturn,
|
|
430
|
+
] extends [never]
|
|
431
|
+
? RouteContext
|
|
432
|
+
: TRouteContextReturn
|
|
433
|
+
|
|
434
|
+
export type ResolveAllContext<
|
|
435
|
+
TParentRoute extends AnyRoute,
|
|
436
|
+
TRouteContext,
|
|
437
|
+
> = Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
438
|
+
|
|
439
|
+
export type ResolveLoaderData<TLoaderDataReturn> = [TLoaderDataReturn] extends [
|
|
440
|
+
never,
|
|
441
|
+
]
|
|
442
|
+
? undefined
|
|
443
|
+
: TLoaderDataReturn
|
|
415
444
|
|
|
416
445
|
export interface AnyRoute
|
|
417
446
|
extends Route<
|
|
@@ -437,8 +466,12 @@ export interface AnyRoute
|
|
|
437
466
|
any
|
|
438
467
|
> {}
|
|
439
468
|
|
|
440
|
-
|
|
441
|
-
|
|
469
|
+
export type ResolveAllParamsFromParent<
|
|
470
|
+
TParentRoute extends AnyRoute,
|
|
471
|
+
TParams,
|
|
472
|
+
> = unknown extends TParentRoute
|
|
473
|
+
? TParams
|
|
474
|
+
: Assign<TParentRoute['types']['allParams'], TParams>
|
|
442
475
|
|
|
443
476
|
export type ResolveAllParams<TParentRoute extends AnyRoute, TParams> =
|
|
444
477
|
Record<never, string> extends TParentRoute['types']['allParams']
|
|
@@ -566,11 +599,12 @@ export class Route<
|
|
|
566
599
|
TCustomId,
|
|
567
600
|
TPath
|
|
568
601
|
>,
|
|
569
|
-
in out TSearchSchemaInput
|
|
570
|
-
in out TSearchSchema
|
|
571
|
-
in out TSearchSchemaUsed =
|
|
572
|
-
|
|
573
|
-
|
|
602
|
+
in out TSearchSchemaInput = {},
|
|
603
|
+
in out TSearchSchema = {},
|
|
604
|
+
in out TSearchSchemaUsed = ResolveSearchSchemaUsed<
|
|
605
|
+
TSearchSchemaInput,
|
|
606
|
+
TSearchSchema
|
|
607
|
+
>,
|
|
574
608
|
in out TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
575
609
|
TParentRoute,
|
|
576
610
|
TSearchSchemaUsed
|
|
@@ -581,21 +615,17 @@ export class Route<
|
|
|
581
615
|
>,
|
|
582
616
|
in out TParams = Record<ParsePathParams<TPath>, string>,
|
|
583
617
|
in out TAllParams = ResolveAllParams<TParentRoute, TParams>,
|
|
584
|
-
TRouteContextReturn
|
|
585
|
-
in out TRouteContext =
|
|
586
|
-
? RouteContext
|
|
587
|
-
: TRouteContextReturn,
|
|
618
|
+
TRouteContextReturn = RouteContext,
|
|
619
|
+
in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
|
|
588
620
|
in out TAllContext = Assign<
|
|
589
621
|
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
590
622
|
TRouteContext
|
|
591
623
|
>,
|
|
592
|
-
in out TRouterContext
|
|
624
|
+
in out TRouterContext = AnyContext,
|
|
593
625
|
in out TLoaderDeps extends Record<string, any> = {},
|
|
594
626
|
TLoaderDataReturn = unknown,
|
|
595
|
-
in out TLoaderData =
|
|
596
|
-
|
|
597
|
-
: TLoaderDataReturn,
|
|
598
|
-
in out TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
627
|
+
in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
|
|
628
|
+
in out TChildren = unknown,
|
|
599
629
|
> {
|
|
600
630
|
isRoot: TParentRoute extends Route<any> ? true : false
|
|
601
631
|
options: RouteOptions<
|
|
@@ -764,7 +794,11 @@ export class Route<
|
|
|
764
794
|
this.to = fullPath as TrimPathRight<TFullPath>
|
|
765
795
|
}
|
|
766
796
|
|
|
767
|
-
addChildren = <
|
|
797
|
+
addChildren = <
|
|
798
|
+
const TNewChildren extends
|
|
799
|
+
| Record<string, AnyRoute>
|
|
800
|
+
| ReadonlyArray<AnyRoute>,
|
|
801
|
+
>(
|
|
768
802
|
children: TNewChildren,
|
|
769
803
|
): Route<
|
|
770
804
|
TParentRoute,
|
|
@@ -788,7 +822,9 @@ export class Route<
|
|
|
788
822
|
TLoaderData,
|
|
789
823
|
TNewChildren
|
|
790
824
|
> => {
|
|
791
|
-
this.children =
|
|
825
|
+
this.children = (
|
|
826
|
+
Array.isArray(children) ? children : Object.values(children)
|
|
827
|
+
) as any
|
|
792
828
|
return this as any
|
|
793
829
|
}
|
|
794
830
|
|
|
@@ -907,11 +943,12 @@ export function createRoute<
|
|
|
907
943
|
TCustomId,
|
|
908
944
|
TPath
|
|
909
945
|
>,
|
|
910
|
-
TSearchSchemaInput
|
|
911
|
-
TSearchSchema
|
|
912
|
-
TSearchSchemaUsed =
|
|
913
|
-
|
|
914
|
-
|
|
946
|
+
TSearchSchemaInput = {},
|
|
947
|
+
TSearchSchema = {},
|
|
948
|
+
TSearchSchemaUsed = ResolveSearchSchemaUsed<
|
|
949
|
+
TSearchSchemaInput,
|
|
950
|
+
TSearchSchema
|
|
951
|
+
>,
|
|
915
952
|
TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
916
953
|
TParentRoute,
|
|
917
954
|
TSearchSchemaUsed
|
|
@@ -919,21 +956,17 @@ export function createRoute<
|
|
|
919
956
|
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
920
957
|
TParams = Record<ParsePathParams<TPath>, string>,
|
|
921
958
|
TAllParams = ResolveAllParams<TParentRoute, TParams>,
|
|
922
|
-
TRouteContextReturn
|
|
923
|
-
TRouteContext =
|
|
924
|
-
? RouteContext
|
|
925
|
-
: TRouteContextReturn,
|
|
959
|
+
TRouteContextReturn = RouteContext,
|
|
960
|
+
TRouteContext = ResolveRouteContext<TRouteContextReturn>,
|
|
926
961
|
TAllContext = Assign<
|
|
927
962
|
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
928
963
|
TRouteContext
|
|
929
964
|
>,
|
|
930
|
-
TRouterContext
|
|
965
|
+
TRouterContext = AnyContext,
|
|
931
966
|
TLoaderDeps extends Record<string, any> = {},
|
|
932
967
|
TLoaderDataReturn = unknown,
|
|
933
|
-
TLoaderData =
|
|
934
|
-
|
|
935
|
-
: TLoaderDataReturn,
|
|
936
|
-
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
968
|
+
TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
|
|
969
|
+
TChildren = unknown,
|
|
937
970
|
>(
|
|
938
971
|
options: RouteOptions<
|
|
939
972
|
TParentRoute,
|
|
@@ -982,19 +1015,15 @@ export function createRoute<
|
|
|
982
1015
|
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
|
|
983
1016
|
|
|
984
1017
|
export type RootRouteOptions<
|
|
985
|
-
TSearchSchemaInput
|
|
986
|
-
TSearchSchema
|
|
987
|
-
TSearchSchemaUsed
|
|
988
|
-
TRouteContextReturn
|
|
989
|
-
TRouteContext
|
|
990
|
-
|
|
991
|
-
: TRouteContextReturn,
|
|
992
|
-
TRouterContext extends {} = {},
|
|
1018
|
+
TSearchSchemaInput = RootSearchSchema,
|
|
1019
|
+
TSearchSchema = RootSearchSchema,
|
|
1020
|
+
TSearchSchemaUsed = RootSearchSchema,
|
|
1021
|
+
TRouteContextReturn = RouteContext,
|
|
1022
|
+
TRouteContext = ResolveRouteContext<TRouteContextReturn>,
|
|
1023
|
+
TRouterContext = {},
|
|
993
1024
|
TLoaderDeps extends Record<string, any> = {},
|
|
994
1025
|
TLoaderDataReturn = unknown,
|
|
995
|
-
TLoaderData =
|
|
996
|
-
? undefined
|
|
997
|
-
: TLoaderDataReturn,
|
|
1026
|
+
TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
|
|
998
1027
|
> = Omit<
|
|
999
1028
|
RouteOptions<
|
|
1000
1029
|
any, // TParentRoute
|
|
@@ -1073,21 +1102,15 @@ export type RootSearchSchema = {
|
|
|
1073
1102
|
}
|
|
1074
1103
|
|
|
1075
1104
|
export class RootRoute<
|
|
1076
|
-
in out TSearchSchemaInput
|
|
1077
|
-
in out TSearchSchema
|
|
1078
|
-
in out TSearchSchemaUsed
|
|
1079
|
-
TRouteContextReturn
|
|
1080
|
-
in out TRouteContext
|
|
1081
|
-
|
|
1082
|
-
]
|
|
1083
|
-
? RouteContext
|
|
1084
|
-
: TRouteContextReturn,
|
|
1085
|
-
in out TRouterContext extends {} = {},
|
|
1105
|
+
in out TSearchSchemaInput = RootSearchSchema,
|
|
1106
|
+
in out TSearchSchema = RootSearchSchema,
|
|
1107
|
+
in out TSearchSchemaUsed = RootSearchSchema,
|
|
1108
|
+
TRouteContextReturn = RouteContext,
|
|
1109
|
+
in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
|
|
1110
|
+
in out TRouterContext = {},
|
|
1086
1111
|
TLoaderDeps extends Record<string, any> = {},
|
|
1087
1112
|
TLoaderDataReturn = unknown,
|
|
1088
|
-
in out TLoaderData =
|
|
1089
|
-
? undefined
|
|
1090
|
-
: TLoaderDataReturn,
|
|
1113
|
+
in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
|
|
1091
1114
|
> extends Route<
|
|
1092
1115
|
any, // TParentRoute
|
|
1093
1116
|
'/', // TPath
|
|
@@ -1131,19 +1154,15 @@ export class RootRoute<
|
|
|
1131
1154
|
}
|
|
1132
1155
|
|
|
1133
1156
|
export function createRootRoute<
|
|
1134
|
-
TSearchSchemaInput
|
|
1135
|
-
TSearchSchema
|
|
1136
|
-
TSearchSchemaUsed
|
|
1137
|
-
TRouteContextReturn
|
|
1138
|
-
TRouteContext
|
|
1139
|
-
|
|
1140
|
-
: TRouteContextReturn,
|
|
1141
|
-
TRouterContext extends {} = {},
|
|
1157
|
+
TSearchSchemaInput = RootSearchSchema,
|
|
1158
|
+
TSearchSchema = RootSearchSchema,
|
|
1159
|
+
TSearchSchemaUsed = RootSearchSchema,
|
|
1160
|
+
TRouteContextReturn = RouteContext,
|
|
1161
|
+
TRouteContext = ResolveRouteContext<TRouteContextReturn>,
|
|
1162
|
+
TRouterContext = {},
|
|
1142
1163
|
TLoaderDeps extends Record<string, any> = {},
|
|
1143
1164
|
TLoaderDataReturn = unknown,
|
|
1144
|
-
TLoaderData =
|
|
1145
|
-
? undefined
|
|
1146
|
-
: TLoaderDataReturn,
|
|
1165
|
+
TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
|
|
1147
1166
|
>(
|
|
1148
1167
|
options?: Omit<
|
|
1149
1168
|
RouteOptions<
|
|
@@ -1276,8 +1295,7 @@ export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
|
1276
1295
|
preload?: () => Promise<void>
|
|
1277
1296
|
}
|
|
1278
1297
|
|
|
1279
|
-
export type RouteComponent<TProps = any> =
|
|
1280
|
-
AsyncRouteComponent<TProps>
|
|
1298
|
+
export type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>
|
|
1281
1299
|
|
|
1282
1300
|
export type ErrorRouteComponent = RouteComponent<ErrorComponentProps>
|
|
1283
1301
|
|
|
@@ -1286,27 +1304,24 @@ export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>
|
|
|
1286
1304
|
export class NotFoundRoute<
|
|
1287
1305
|
TParentRoute extends AnyRootRoute,
|
|
1288
1306
|
TSearchSchemaInput extends Record<string, any> = {},
|
|
1289
|
-
TSearchSchema
|
|
1290
|
-
TSearchSchemaUsed
|
|
1291
|
-
TFullSearchSchemaInput
|
|
1292
|
-
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<
|
|
1307
|
+
TSearchSchema = {},
|
|
1308
|
+
TSearchSchemaUsed = {},
|
|
1309
|
+
TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
1293
1310
|
TParentRoute,
|
|
1294
1311
|
TSearchSchemaUsed
|
|
1295
1312
|
>,
|
|
1296
1313
|
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
1297
|
-
TRouteContextReturn
|
|
1298
|
-
TRouteContext
|
|
1314
|
+
TRouteContextReturn = AnyContext,
|
|
1315
|
+
TRouteContext = RouteContext,
|
|
1299
1316
|
TAllContext = Assign<
|
|
1300
1317
|
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
1301
1318
|
TRouteContext
|
|
1302
1319
|
>,
|
|
1303
|
-
TRouterContext
|
|
1320
|
+
TRouterContext = AnyContext,
|
|
1304
1321
|
TLoaderDeps extends Record<string, any> = {},
|
|
1305
1322
|
TLoaderDataReturn = unknown,
|
|
1306
|
-
TLoaderData =
|
|
1307
|
-
|
|
1308
|
-
: TLoaderDataReturn,
|
|
1309
|
-
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
1323
|
+
TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
|
|
1324
|
+
TChildren = unknown,
|
|
1310
1325
|
> extends Route<
|
|
1311
1326
|
TParentRoute,
|
|
1312
1327
|
'/404',
|
package/src/routeInfo.ts
CHANGED
|
@@ -5,19 +5,28 @@ import type { UnionToIntersection, UnionToTuple } from './utils'
|
|
|
5
5
|
export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
|
|
6
6
|
types: { children: infer TChildren }
|
|
7
7
|
}
|
|
8
|
-
?
|
|
9
|
-
?
|
|
10
|
-
:
|
|
8
|
+
? unknown extends TChildren
|
|
9
|
+
? TAcc
|
|
10
|
+
: TChildren extends ReadonlyArray<any>
|
|
11
|
+
? ParseRoute<TChildren[number], TAcc | TChildren[number]>
|
|
12
|
+
: ParseRoute<
|
|
13
|
+
TChildren[keyof TChildren],
|
|
14
|
+
TAcc | TChildren[keyof TChildren]
|
|
15
|
+
>
|
|
11
16
|
: TAcc
|
|
12
17
|
|
|
13
18
|
export type ParseRouteWithoutBranches<TRouteTree> =
|
|
14
19
|
ParseRoute<TRouteTree> extends infer TRoute extends AnyRoute
|
|
15
20
|
? TRoute extends any
|
|
16
|
-
? TRoute['types']['children']
|
|
17
|
-
?
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
? unknown extends TRoute['types']['children']
|
|
22
|
+
? TRoute
|
|
23
|
+
: TRoute['types']['children'] extends ReadonlyArray<any>
|
|
24
|
+
? '/' extends TRoute['types']['children'][number]['path']
|
|
25
|
+
? never
|
|
26
|
+
: TRoute
|
|
27
|
+
: '/' extends TRoute['types']['children'][keyof TRoute['types']['children']]['path']
|
|
28
|
+
? never
|
|
29
|
+
: TRoute
|
|
21
30
|
: never
|
|
22
31
|
: never
|
|
23
32
|
|
|
@@ -32,19 +41,14 @@ export type RouteById<TRouteTree extends AnyRoute, TId> = Extract<
|
|
|
32
41
|
|
|
33
42
|
export type RouteIds<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['id']
|
|
34
43
|
|
|
35
|
-
export type CatchAllPaths
|
|
36
|
-
'.' | '..' | '',
|
|
37
|
-
ParseRoute<TRouteTree>
|
|
38
|
-
>
|
|
44
|
+
export type CatchAllPaths = '.' | '..' | ''
|
|
39
45
|
|
|
40
46
|
export type RoutesByPath<TRouteTree extends AnyRoute> = {
|
|
41
47
|
[K in ParseRoute<TRouteTree> as K['fullPath']]: K
|
|
42
|
-
}
|
|
48
|
+
}
|
|
43
49
|
|
|
44
50
|
export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<
|
|
45
|
-
|
|
46
|
-
? ParseRoute<TRouteTree>
|
|
47
|
-
: RoutesByPath<TRouteTree>[TPath],
|
|
51
|
+
RoutesByPath<TRouteTree>[TPath],
|
|
48
52
|
AnyRoute
|
|
49
53
|
>
|
|
50
54
|
|
|
@@ -103,18 +107,16 @@ export type RoutesByToPath<TRouter extends AnyRouter> = {
|
|
|
103
107
|
TRouter,
|
|
104
108
|
TRoute
|
|
105
109
|
>]: TRoute
|
|
106
|
-
}
|
|
110
|
+
}
|
|
107
111
|
|
|
108
112
|
export type RouteByToPath<TRouter extends AnyRouter, TTo> = Extract<
|
|
109
|
-
|
|
110
|
-
? ParseRouteWithoutBranches<TRouter['routeTree']>
|
|
111
|
-
: RoutesByToPath<TRouter>[TTo],
|
|
113
|
+
RoutesByToPath<TRouter>[TTo],
|
|
112
114
|
AnyRoute
|
|
113
115
|
>
|
|
114
116
|
|
|
115
|
-
export type RoutePathsAutoComplete<
|
|
117
|
+
export type RoutePathsAutoComplete<TRouter extends AnyRouter, T> =
|
|
116
118
|
| (string extends T ? T & {} : T)
|
|
117
|
-
| RoutePaths<
|
|
119
|
+
| RoutePaths<TRouter['routeTree']>
|
|
118
120
|
|
|
119
121
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
120
122
|
type UnionizeCollisions<T, U> = {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useRouterState } from './useRouterState'
|
|
2
|
+
import type { AnyRouter, RegisteredRouter, RouterState } from './router'
|
|
3
|
+
|
|
4
|
+
export function useLocation<
|
|
5
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
6
|
+
TLocationState = RouterState<TRouter['routeTree']>['location'],
|
|
7
|
+
TSelected = TLocationState,
|
|
8
|
+
>(opts?: { select?: (state: TLocationState) => TSelected }): TSelected {
|
|
9
|
+
return useRouterState({
|
|
10
|
+
select: (state) =>
|
|
11
|
+
opts?.select
|
|
12
|
+
? opts.select(state.location as TLocationState)
|
|
13
|
+
: (state.location as TSelected),
|
|
14
|
+
})
|
|
15
|
+
}
|
package/src/useNavigate.tsx
CHANGED
|
@@ -20,7 +20,7 @@ export type UseNavigateResult<TDefaultFrom extends string> = <
|
|
|
20
20
|
export function useNavigate<
|
|
21
21
|
TDefaultFrom extends string = string,
|
|
22
22
|
>(_defaultOpts?: {
|
|
23
|
-
from?: RoutePathsAutoComplete<RegisteredRouter
|
|
23
|
+
from?: RoutePathsAutoComplete<RegisteredRouter, TDefaultFrom>
|
|
24
24
|
}): UseNavigateResult<TDefaultFrom> {
|
|
25
25
|
const router = useRouter()
|
|
26
26
|
|
|
@@ -32,7 +32,7 @@ export function useNavigate<
|
|
|
32
32
|
})
|
|
33
33
|
},
|
|
34
34
|
[router],
|
|
35
|
-
)
|
|
35
|
+
) as UseNavigateResult<TDefaultFrom>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// NOTE: I don't know of anyone using this. It's undocumented, so let's wait until someone needs it
|