@tanstack/react-router 1.32.0 → 1.32.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.
Files changed (73) hide show
  1. package/dist/cjs/Matches.d.cts +6 -9
  2. package/dist/cjs/RouterProvider.d.cts +6 -6
  3. package/dist/cjs/awaited.d.cts +1 -1
  4. package/dist/cjs/defer.d.cts +1 -0
  5. package/dist/cjs/fileRoute.cjs.map +1 -1
  6. package/dist/cjs/fileRoute.d.cts +38 -79
  7. package/dist/cjs/index.d.cts +3 -3
  8. package/dist/cjs/lazyRouteComponent.d.cts +2 -1
  9. package/dist/cjs/link.cjs.map +1 -1
  10. package/dist/cjs/link.d.cts +56 -50
  11. package/dist/cjs/location.d.cts +3 -2
  12. package/dist/cjs/not-found.d.cts +2 -2
  13. package/dist/cjs/path.d.cts +3 -2
  14. package/dist/cjs/redirects.d.cts +5 -4
  15. package/dist/cjs/route.cjs +1 -1
  16. package/dist/cjs/route.cjs.map +1 -1
  17. package/dist/cjs/route.d.cts +64 -57
  18. package/dist/cjs/routeInfo.d.cts +12 -11
  19. package/dist/cjs/router.cjs +2 -2
  20. package/dist/cjs/router.cjs.map +1 -1
  21. package/dist/cjs/router.d.cts +19 -20
  22. package/dist/cjs/routerContext.d.cts +1 -1
  23. package/dist/cjs/scroll-restoration.d.cts +2 -1
  24. package/dist/cjs/searchParams.d.cts +2 -1
  25. package/dist/cjs/useBlocker.d.cts +3 -2
  26. package/dist/cjs/useLocation.d.cts +2 -1
  27. package/dist/cjs/useNavigate.cjs.map +1 -1
  28. package/dist/cjs/useNavigate.d.cts +5 -4
  29. package/dist/cjs/useParams.d.cts +5 -5
  30. package/dist/cjs/useRouteContext.d.cts +5 -4
  31. package/dist/cjs/useRouter.d.cts +2 -1
  32. package/dist/cjs/useRouterState.d.cts +2 -1
  33. package/dist/cjs/useSearch.d.cts +5 -4
  34. package/dist/esm/Matches.d.ts +6 -9
  35. package/dist/esm/RouterProvider.d.ts +6 -6
  36. package/dist/esm/awaited.d.ts +1 -1
  37. package/dist/esm/defer.d.ts +1 -0
  38. package/dist/esm/fileRoute.d.ts +38 -79
  39. package/dist/esm/fileRoute.js.map +1 -1
  40. package/dist/esm/index.d.ts +3 -3
  41. package/dist/esm/lazyRouteComponent.d.ts +2 -1
  42. package/dist/esm/link.d.ts +56 -50
  43. package/dist/esm/link.js.map +1 -1
  44. package/dist/esm/location.d.ts +3 -2
  45. package/dist/esm/not-found.d.ts +2 -2
  46. package/dist/esm/path.d.ts +3 -2
  47. package/dist/esm/redirects.d.ts +5 -4
  48. package/dist/esm/route.d.ts +64 -57
  49. package/dist/esm/route.js +1 -1
  50. package/dist/esm/route.js.map +1 -1
  51. package/dist/esm/routeInfo.d.ts +12 -11
  52. package/dist/esm/router.d.ts +19 -20
  53. package/dist/esm/router.js +2 -2
  54. package/dist/esm/router.js.map +1 -1
  55. package/dist/esm/routerContext.d.ts +1 -1
  56. package/dist/esm/scroll-restoration.d.ts +2 -1
  57. package/dist/esm/searchParams.d.ts +2 -1
  58. package/dist/esm/useBlocker.d.ts +3 -2
  59. package/dist/esm/useLocation.d.ts +2 -1
  60. package/dist/esm/useNavigate.d.ts +5 -4
  61. package/dist/esm/useNavigate.js.map +1 -1
  62. package/dist/esm/useParams.d.ts +5 -5
  63. package/dist/esm/useRouteContext.d.ts +5 -4
  64. package/dist/esm/useRouter.d.ts +2 -1
  65. package/dist/esm/useRouterState.d.ts +2 -1
  66. package/dist/esm/useSearch.d.ts +5 -4
  67. package/package.json +2 -10
  68. package/src/fileRoute.ts +26 -104
  69. package/src/index.tsx +0 -8
  70. package/src/link.tsx +205 -156
  71. package/src/route.ts +130 -111
  72. package/src/routeInfo.ts +24 -22
  73. 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 extends Record<string, any> = {},
61
- TSearchSchema extends Record<string, any> = {},
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 extends RouteContext = RouteContext,
67
+ TRouteContextReturn = RouteContext,
68
68
  TRouteContext = RouteContext,
69
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
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 extends Record<string, any> = {},
113
- TSearchSchema extends Record<string, any> = {},
112
+ TSearchSchemaInput = {},
113
+ TSearchSchema = {},
114
114
  TFullSearchSchema = TSearchSchema,
115
115
  TParams = {},
116
116
  TAllParams = ParamsFallback<TPath, TParams>,
117
- TRouteContextReturn extends RouteContext = RouteContext,
117
+ TRouteContextReturn = RouteContext,
118
118
  TRouteContext = RouteContext,
119
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
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 extends Record<string, any> = {},
177
- TSearchSchema extends Record<string, any> = {},
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 extends RouteContext = RouteContext,
183
+ TRouteContextReturn = RouteContext,
184
184
  TRouteContext = RouteContext,
185
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
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 extends RouteContext,
213
- in out TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
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
- > = Assign<
400
- TParentRoute['id'] extends RootRouteId
401
- ? Omit<TParentRoute['types']['searchSchema'], keyof RootSearchSchema>
402
- : TParentRoute['types']['fullSearchSchema'],
403
- TSearchSchema
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
- > = Assign<
410
- TParentRoute['id'] extends RootRouteId
411
- ? Omit<TParentRoute['types']['searchSchemaInput'], keyof RootSearchSchema>
412
- : TParentRoute['types']['fullSearchSchemaInput'],
413
- TSearchSchemaUsed
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
- // eslint-disable-next-line @typescript-eslint/naming-convention
441
- export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>
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']
@@ -465,7 +498,8 @@ export type RouteConstraints = {
465
498
 
466
499
  export function getRouteApi<
467
500
  TId extends RouteIds<RegisteredRouter['routeTree']>,
468
- TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
501
+ TRouter extends AnyRouter = RegisteredRouter,
502
+ TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,
469
503
  TFullSearchSchema = TRoute['types']['fullSearchSchema'],
470
504
  TAllParams = TRoute['types']['allParams'],
471
505
  TAllContext = TRoute['types']['allContext'],
@@ -474,6 +508,7 @@ export function getRouteApi<
474
508
  >(id: TId) {
475
509
  return new RouteApi<
476
510
  TId,
511
+ TRouter,
477
512
  TRoute,
478
513
  TFullSearchSchema,
479
514
  TAllParams,
@@ -485,7 +520,8 @@ export function getRouteApi<
485
520
 
486
521
  export class RouteApi<
487
522
  TId extends RouteIds<RegisteredRouter['routeTree']>,
488
- TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
523
+ TRouter extends AnyRouter = RegisteredRouter,
524
+ TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,
489
525
  TFullSearchSchema = TRoute['types']['fullSearchSchema'],
490
526
  TAllParams = TRoute['types']['allParams'],
491
527
  TAllContext = TRoute['types']['allContext'],
@@ -502,7 +538,7 @@ export class RouteApi<
502
538
  }
503
539
 
504
540
  useMatch = <
505
- TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
541
+ TRouteTree extends AnyRoute = TRouter['routeTree'],
506
542
  TRouteMatch = MakeRouteMatch<TRouteTree, TId>,
507
543
  TSelected = TRouteMatch,
508
544
  >(opts?: {
@@ -544,7 +580,7 @@ export class RouteApi<
544
580
  return useLoaderData({ ...opts, from: this.id, strict: false } as any)
545
581
  }
546
582
 
547
- useNavigate = () => {
583
+ useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {
548
584
  return useNavigate({ from: this.id })
549
585
  }
550
586
 
@@ -566,11 +602,12 @@ export class Route<
566
602
  TCustomId,
567
603
  TPath
568
604
  >,
569
- in out TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
570
- in out TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
571
- in out TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
572
- ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
573
- : TSearchSchema,
605
+ in out TSearchSchemaInput = {},
606
+ in out TSearchSchema = {},
607
+ in out TSearchSchemaUsed = ResolveSearchSchemaUsed<
608
+ TSearchSchemaInput,
609
+ TSearchSchema
610
+ >,
574
611
  in out TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
575
612
  TParentRoute,
576
613
  TSearchSchemaUsed
@@ -581,21 +618,17 @@ export class Route<
581
618
  >,
582
619
  in out TParams = Record<ParsePathParams<TPath>, string>,
583
620
  in out TAllParams = ResolveAllParams<TParentRoute, TParams>,
584
- TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
585
- in out TRouteContext = [TRouteContextReturn] extends [never]
586
- ? RouteContext
587
- : TRouteContextReturn,
621
+ TRouteContextReturn = RouteContext,
622
+ in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
588
623
  in out TAllContext = Assign<
589
624
  IsAny<TParentRoute['types']['allContext'], {}>,
590
625
  TRouteContext
591
626
  >,
592
- in out TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
627
+ in out TRouterContext = AnyContext,
593
628
  in out TLoaderDeps extends Record<string, any> = {},
594
629
  TLoaderDataReturn = unknown,
595
- in out TLoaderData = [TLoaderDataReturn] extends [never]
596
- ? undefined
597
- : TLoaderDataReturn,
598
- in out TChildren extends RouteConstraints['TChildren'] = unknown,
630
+ in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
631
+ in out TChildren = unknown,
599
632
  > {
600
633
  isRoot: TParentRoute extends Route<any> ? true : false
601
634
  options: RouteOptions<
@@ -764,7 +797,11 @@ export class Route<
764
797
  this.to = fullPath as TrimPathRight<TFullPath>
765
798
  }
766
799
 
767
- addChildren = <const TNewChildren extends ReadonlyArray<AnyRoute>>(
800
+ addChildren = <
801
+ const TNewChildren extends
802
+ | Record<string, AnyRoute>
803
+ | ReadonlyArray<AnyRoute>,
804
+ >(
768
805
  children: TNewChildren,
769
806
  ): Route<
770
807
  TParentRoute,
@@ -788,7 +825,9 @@ export class Route<
788
825
  TLoaderData,
789
826
  TNewChildren
790
827
  > => {
791
- this.children = children as any
828
+ this.children = (
829
+ Array.isArray(children) ? children : Object.values(children)
830
+ ) as any
792
831
  return this as any
793
832
  }
794
833
 
@@ -846,7 +885,8 @@ export class Route<
846
885
  }
847
886
 
848
887
  useMatch = <
849
- TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
888
+ TRouter extends AnyRouter = RegisteredRouter,
889
+ TRouteTree extends AnyRoute = TRouter['routeTree'],
850
890
  TRouteMatch = MakeRouteMatch<TRouteTree, TId>,
851
891
  TSelected = TRouteMatch,
852
892
  >(opts?: {
@@ -907,11 +947,12 @@ export function createRoute<
907
947
  TCustomId,
908
948
  TPath
909
949
  >,
910
- TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
911
- TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
912
- TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
913
- ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
914
- : TSearchSchema,
950
+ TSearchSchemaInput = {},
951
+ TSearchSchema = {},
952
+ TSearchSchemaUsed = ResolveSearchSchemaUsed<
953
+ TSearchSchemaInput,
954
+ TSearchSchema
955
+ >,
915
956
  TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
916
957
  TParentRoute,
917
958
  TSearchSchemaUsed
@@ -919,21 +960,17 @@ export function createRoute<
919
960
  TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
920
961
  TParams = Record<ParsePathParams<TPath>, string>,
921
962
  TAllParams = ResolveAllParams<TParentRoute, TParams>,
922
- TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
923
- TRouteContext = [TRouteContextReturn] extends [never]
924
- ? RouteContext
925
- : TRouteContextReturn,
963
+ TRouteContextReturn = RouteContext,
964
+ TRouteContext = ResolveRouteContext<TRouteContextReturn>,
926
965
  TAllContext = Assign<
927
966
  IsAny<TParentRoute['types']['allContext'], {}>,
928
967
  TRouteContext
929
968
  >,
930
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
969
+ TRouterContext = AnyContext,
931
970
  TLoaderDeps extends Record<string, any> = {},
932
971
  TLoaderDataReturn = unknown,
933
- TLoaderData = [TLoaderDataReturn] extends [never]
934
- ? undefined
935
- : TLoaderDataReturn,
936
- TChildren extends RouteConstraints['TChildren'] = unknown,
972
+ TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
973
+ TChildren = unknown,
937
974
  >(
938
975
  options: RouteOptions<
939
976
  TParentRoute,
@@ -982,19 +1019,15 @@ export function createRoute<
982
1019
  export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
983
1020
 
984
1021
  export type RootRouteOptions<
985
- TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
986
- TSearchSchema extends Record<string, any> = RootSearchSchema,
987
- TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
988
- TRouteContextReturn extends RouteContext = RouteContext,
989
- TRouteContext extends RouteContext = [TRouteContextReturn] extends [never]
990
- ? RouteContext
991
- : TRouteContextReturn,
992
- TRouterContext extends {} = {},
1022
+ TSearchSchemaInput = RootSearchSchema,
1023
+ TSearchSchema = RootSearchSchema,
1024
+ TSearchSchemaUsed = RootSearchSchema,
1025
+ TRouteContextReturn = RouteContext,
1026
+ TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1027
+ TRouterContext = {},
993
1028
  TLoaderDeps extends Record<string, any> = {},
994
1029
  TLoaderDataReturn = unknown,
995
- TLoaderData = [TLoaderDataReturn] extends [never]
996
- ? undefined
997
- : TLoaderDataReturn,
1030
+ TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
998
1031
  > = Omit<
999
1032
  RouteOptions<
1000
1033
  any, // TParentRoute
@@ -1073,21 +1106,15 @@ export type RootSearchSchema = {
1073
1106
  }
1074
1107
 
1075
1108
  export class RootRoute<
1076
- in out TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
1077
- in out TSearchSchema extends Record<string, any> = RootSearchSchema,
1078
- in out TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
1079
- TRouteContextReturn extends RouteContext = RouteContext,
1080
- in out TRouteContext extends RouteContext = [TRouteContextReturn] extends [
1081
- never,
1082
- ]
1083
- ? RouteContext
1084
- : TRouteContextReturn,
1085
- in out TRouterContext extends {} = {},
1109
+ in out TSearchSchemaInput = RootSearchSchema,
1110
+ in out TSearchSchema = RootSearchSchema,
1111
+ in out TSearchSchemaUsed = RootSearchSchema,
1112
+ TRouteContextReturn = RouteContext,
1113
+ in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1114
+ in out TRouterContext = {},
1086
1115
  TLoaderDeps extends Record<string, any> = {},
1087
1116
  TLoaderDataReturn = unknown,
1088
- in out TLoaderData = [TLoaderDataReturn] extends [never]
1089
- ? undefined
1090
- : TLoaderDataReturn,
1117
+ in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
1091
1118
  > extends Route<
1092
1119
  any, // TParentRoute
1093
1120
  '/', // TPath
@@ -1131,19 +1158,15 @@ export class RootRoute<
1131
1158
  }
1132
1159
 
1133
1160
  export function createRootRoute<
1134
- TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
1135
- TSearchSchema extends Record<string, any> = RootSearchSchema,
1136
- TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
1137
- TRouteContextReturn extends RouteContext = RouteContext,
1138
- TRouteContext extends RouteContext = [TRouteContextReturn] extends [never]
1139
- ? RouteContext
1140
- : TRouteContextReturn,
1141
- TRouterContext extends {} = {},
1161
+ TSearchSchemaInput = RootSearchSchema,
1162
+ TSearchSchema = RootSearchSchema,
1163
+ TSearchSchemaUsed = RootSearchSchema,
1164
+ TRouteContextReturn = RouteContext,
1165
+ TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1166
+ TRouterContext = {},
1142
1167
  TLoaderDeps extends Record<string, any> = {},
1143
1168
  TLoaderDataReturn = unknown,
1144
- TLoaderData = [TLoaderDataReturn] extends [never]
1145
- ? undefined
1146
- : TLoaderDataReturn,
1169
+ TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
1147
1170
  >(
1148
1171
  options?: Omit<
1149
1172
  RouteOptions<
@@ -1276,8 +1299,7 @@ export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
1276
1299
  preload?: () => Promise<void>
1277
1300
  }
1278
1301
 
1279
- export type RouteComponent<TProps = any> = SyncRouteComponent<TProps> &
1280
- AsyncRouteComponent<TProps>
1302
+ export type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>
1281
1303
 
1282
1304
  export type ErrorRouteComponent = RouteComponent<ErrorComponentProps>
1283
1305
 
@@ -1286,27 +1308,24 @@ export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>
1286
1308
  export class NotFoundRoute<
1287
1309
  TParentRoute extends AnyRootRoute,
1288
1310
  TSearchSchemaInput extends Record<string, any> = {},
1289
- TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
1290
- TSearchSchemaUsed extends RouteConstraints['TSearchSchema'] = {},
1291
- TFullSearchSchemaInput extends
1292
- RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<
1311
+ TSearchSchema = {},
1312
+ TSearchSchemaUsed = {},
1313
+ TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
1293
1314
  TParentRoute,
1294
1315
  TSearchSchemaUsed
1295
1316
  >,
1296
1317
  TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
1297
- TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext,
1298
- TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
1318
+ TRouteContextReturn = AnyContext,
1319
+ TRouteContext = RouteContext,
1299
1320
  TAllContext = Assign<
1300
1321
  IsAny<TParentRoute['types']['allContext'], {}>,
1301
1322
  TRouteContext
1302
1323
  >,
1303
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
1324
+ TRouterContext = AnyContext,
1304
1325
  TLoaderDeps extends Record<string, any> = {},
1305
1326
  TLoaderDataReturn = unknown,
1306
- TLoaderData = [TLoaderDataReturn] extends [never]
1307
- ? undefined
1308
- : TLoaderDataReturn,
1309
- TChildren extends RouteConstraints['TChildren'] = unknown,
1327
+ TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
1328
+ TChildren = unknown,
1310
1329
  > extends Route<
1311
1330
  TParentRoute,
1312
1331
  '/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
- ? TChildren extends ReadonlyArray<any>
9
- ? ParseRoute<TChildren[number], TAcc | TChildren[number]>
10
- : TAcc
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'] extends ReadonlyArray<any>
17
- ? '/' extends TRoute['types']['children'][number]['path']
18
- ? never
19
- : TRoute
20
- : TRoute
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<TRouteTree extends AnyRoute> = Record<
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
- } & CatchAllPaths<TRouteTree>
48
+ }
43
49
 
44
50
  export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<
45
- string extends TPath
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
- } & CatchAllPaths<TRouter['routeTree']>
110
+ }
107
111
 
108
112
  export type RouteByToPath<TRouter extends AnyRouter, TTo> = Extract<
109
- string extends TTo
110
- ? ParseRouteWithoutBranches<TRouter['routeTree']>
111
- : RoutesByToPath<TRouter>[TTo],
113
+ RoutesByToPath<TRouter>[TTo],
112
114
  AnyRoute
113
115
  >
114
116
 
115
- export type RoutePathsAutoComplete<TRouteTree extends AnyRoute, T> =
117
+ export type RoutePathsAutoComplete<TRouter extends AnyRouter, T> =
116
118
  | (string extends T ? T & {} : T)
117
- | RoutePaths<TRouteTree>
119
+ | RoutePaths<TRouter['routeTree']>
118
120
 
119
121
  // eslint-disable-next-line @typescript-eslint/naming-convention
120
122
  type UnionizeCollisions<T, U> = {
@@ -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['routeTree'], TDefaultFrom>
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