@tanstack/react-router 1.48.4 → 1.49.1

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 (56) hide show
  1. package/dist/cjs/Matches.cjs +3 -1
  2. package/dist/cjs/Matches.cjs.map +1 -1
  3. package/dist/cjs/Matches.d.cts +5 -4
  4. package/dist/cjs/fileRoute.cjs.map +1 -1
  5. package/dist/cjs/fileRoute.d.cts +4 -5
  6. package/dist/cjs/index.cjs +2 -0
  7. package/dist/cjs/index.cjs.map +1 -1
  8. package/dist/cjs/index.d.cts +3 -1
  9. package/dist/cjs/link.cjs.map +1 -1
  10. package/dist/cjs/link.d.cts +1 -1
  11. package/dist/cjs/path.cjs +6 -9
  12. package/dist/cjs/path.cjs.map +1 -1
  13. package/dist/cjs/route.cjs +1 -1
  14. package/dist/cjs/route.cjs.map +1 -1
  15. package/dist/cjs/route.d.cts +80 -61
  16. package/dist/cjs/router.cjs +90 -57
  17. package/dist/cjs/router.cjs.map +1 -1
  18. package/dist/cjs/router.d.cts +22 -9
  19. package/dist/cjs/transformer.cjs +39 -0
  20. package/dist/cjs/transformer.cjs.map +1 -0
  21. package/dist/cjs/transformer.d.cts +5 -0
  22. package/dist/cjs/utils.cjs.map +1 -1
  23. package/dist/cjs/utils.d.cts +1 -0
  24. package/dist/esm/Matches.d.ts +5 -4
  25. package/dist/esm/Matches.js +3 -1
  26. package/dist/esm/Matches.js.map +1 -1
  27. package/dist/esm/fileRoute.d.ts +4 -5
  28. package/dist/esm/fileRoute.js.map +1 -1
  29. package/dist/esm/index.d.ts +3 -1
  30. package/dist/esm/index.js +2 -0
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/link.d.ts +1 -1
  33. package/dist/esm/link.js.map +1 -1
  34. package/dist/esm/path.js +6 -9
  35. package/dist/esm/path.js.map +1 -1
  36. package/dist/esm/route.d.ts +80 -61
  37. package/dist/esm/route.js +1 -1
  38. package/dist/esm/route.js.map +1 -1
  39. package/dist/esm/router.d.ts +22 -9
  40. package/dist/esm/router.js +91 -58
  41. package/dist/esm/router.js.map +1 -1
  42. package/dist/esm/transformer.d.ts +5 -0
  43. package/dist/esm/transformer.js +39 -0
  44. package/dist/esm/transformer.js.map +1 -0
  45. package/dist/esm/utils.d.ts +1 -0
  46. package/dist/esm/utils.js.map +1 -1
  47. package/package.json +2 -2
  48. package/src/Matches.tsx +11 -7
  49. package/src/fileRoute.ts +28 -22
  50. package/src/index.tsx +5 -1
  51. package/src/link.tsx +10 -6
  52. package/src/path.ts +7 -10
  53. package/src/route.ts +375 -190
  54. package/src/router.ts +144 -75
  55. package/src/transformer.ts +49 -0
  56. package/src/utils.ts +5 -0
package/src/route.ts CHANGED
@@ -16,7 +16,7 @@ import type { NavigateOptions, ParsePathParams, ToMaskOptions } from './link'
16
16
  import type { ParsedLocation } from './location'
17
17
  import type { RouteById, RouteIds, RoutePaths } from './routeInfo'
18
18
  import type { AnyRouter, RegisteredRouter, Router } from './router'
19
- import type { Assign, Expand, NoInfer, PickRequired } from './utils'
19
+ import type { Assign, Constrain, Expand, NoInfer, PickRequired } from './utils'
20
20
  import type { BuildLocationFn, NavigateFn } from './RouterProvider'
21
21
  import type { NotFoundError } from './not-found'
22
22
  import type { LazyRoute } from './fileRoute'
@@ -57,25 +57,23 @@ export type RouteOptions<
57
57
  TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
58
58
  TParams = AnyPathParams,
59
59
  TAllParams = TParams,
60
- TRouteContextReturn = RouteContext,
61
- TRouteContext = RouteContext,
62
- TParentAllContext = AnyContext,
63
- TAllContext = AnyContext,
64
60
  TLoaderDeps extends Record<string, any> = {},
65
61
  TLoaderDataReturn = {},
66
62
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
63
+ TRouterContext = {},
64
+ TRouteContextFn = AnyContext,
65
+ TBeforeLoadFn = AnyContext,
67
66
  > = BaseRouteOptions<
68
67
  TParentRoute,
69
68
  TCustomId,
70
69
  TPath,
71
70
  TSearchValidator,
72
71
  TParams,
73
- TAllParams,
74
- TRouteContextReturn,
75
- TParentAllContext,
76
- TAllContext,
77
72
  TLoaderDeps,
78
- TLoaderDataReturn
73
+ TLoaderDataReturn,
74
+ TRouterContext,
75
+ TRouteContextFn,
76
+ TBeforeLoadFn
79
77
  > &
80
78
  UpdatableRouteOptions<
81
79
  NoInfer<TParentRoute>,
@@ -83,20 +81,36 @@ export type RouteOptions<
83
81
  NoInfer<TAllParams>,
84
82
  NoInfer<TSearchValidator>,
85
83
  NoInfer<TLoaderData>,
86
- NoInfer<TAllContext>,
87
- NoInfer<TRouteContext>,
88
- NoInfer<TLoaderDeps>
84
+ NoInfer<TLoaderDeps>,
85
+ NoInfer<TRouterContext>,
86
+ NoInfer<TRouteContextFn>,
87
+ NoInfer<TBeforeLoadFn>
89
88
  >
90
89
 
90
+ export type ParseSplatParams<TPath extends string> = TPath extends `${string}$`
91
+ ? '_splat'
92
+ : TPath extends `${string}$/${string}`
93
+ ? '_splat'
94
+ : never
95
+
96
+ export interface SplatParams {
97
+ _splat?: string
98
+ }
99
+
100
+ export type ResolveParams<TPath extends string> =
101
+ ParseSplatParams<TPath> extends never
102
+ ? Record<ParsePathParams<TPath>, string>
103
+ : Record<ParsePathParams<TPath>, string> & SplatParams
104
+
91
105
  export type ParseParamsFn<TPath extends string, TParams> = (
92
- rawParams: Record<ParsePathParams<TPath>, string>,
106
+ rawParams: ResolveParams<TPath>,
93
107
  ) => TParams extends Record<ParsePathParams<TPath>, any>
94
108
  ? TParams
95
109
  : Record<ParsePathParams<TPath>, any>
96
110
 
97
111
  export type StringifyParamsFn<TPath extends string, TParams> = (
98
112
  params: TParams,
99
- ) => Record<ParsePathParams<TPath>, string>
113
+ ) => ResolveParams<TPath>
100
114
 
101
115
  export type ParamsOptions<TPath extends string, TParams> = {
102
116
  params?: {
@@ -115,52 +129,103 @@ export type ParamsOptions<TPath extends string, TParams> = {
115
129
  stringifyParams?: StringifyParamsFn<TPath, TParams>
116
130
  }
117
131
 
118
- export interface FullSearchSchemaOption<TFullSearchSchema> {
119
- search: TFullSearchSchema
132
+ export interface FullSearchSchemaOption<
133
+ in out TParentRoute extends AnyRoute,
134
+ in out TSearchValidator extends AnySearchValidator,
135
+ > {
136
+ search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>
120
137
  }
121
138
 
139
+ export type RouteContextFn<
140
+ in out TParentRoute extends AnyRoute,
141
+ in out TSearchValidator extends AnySearchValidator,
142
+ in out TParams,
143
+ in out TRouterContext,
144
+ > = (
145
+ ctx: RouteContextOptions<
146
+ TParentRoute,
147
+ TSearchValidator,
148
+ TParams,
149
+ TRouterContext
150
+ >,
151
+ ) => any
152
+
153
+ export type BeforeLoadFn<
154
+ in out TParentRoute extends AnyRoute,
155
+ in out TSearchValidator extends AnySearchValidator,
156
+ in out TParams,
157
+ in out TRouterContext,
158
+ in out TRouteContextFn,
159
+ > = (
160
+ ctx: BeforeLoadContextOptions<
161
+ TParentRoute,
162
+ TSearchValidator,
163
+ TParams,
164
+ TRouterContext,
165
+ TRouteContextFn
166
+ >,
167
+ ) => any
168
+
122
169
  export type FileBaseRouteOptions<
123
170
  TParentRoute extends AnyRoute = AnyRoute,
124
171
  TPath extends string = string,
125
172
  TSearchValidator extends AnySearchValidator = undefined,
126
173
  TParams = {},
127
- TAllParams = {},
128
- TRouteContextReturn = RouteContext,
129
- TParentAllContext = AnyContext,
130
- TAllContext = AnyContext,
131
174
  TLoaderDeps extends Record<string, any> = {},
132
175
  TLoaderDataReturn = {},
133
- > = {
176
+ TRouterContext = {},
177
+ TRouteContextFn = AnyContext,
178
+ TBeforeLoadFn = AnyContext,
179
+ > = ParamsOptions<TPath, TParams> & {
134
180
  validateSearch?: TSearchValidator
135
181
  shouldReload?:
136
182
  | boolean
137
183
  | ((
138
184
  match: LoaderFnContext<
139
- TAllParams,
140
- ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
141
- TAllContext
185
+ TParentRoute,
186
+ TParams,
187
+ TLoaderDeps,
188
+ TRouterContext,
189
+ TRouteContextFn,
190
+ TBeforeLoadFn
142
191
  >,
143
192
  ) => any)
193
+
194
+ context?: Constrain<
195
+ TRouteContextFn,
196
+ RouteContextFn<TParentRoute, TSearchValidator, TParams, TRouterContext>
197
+ >
198
+
144
199
  // This async function is called before a route is loaded.
145
200
  // If an error is thrown here, the route's loader will not be called.
146
201
  // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.
147
202
  // If thrown during a preload event, the error will be logged to the console.
148
- beforeLoad?: (
149
- ctx: BeforeLoadContext<
150
- ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
151
- TAllParams,
152
- TParentAllContext
153
- >,
154
- ) => Promise<TRouteContextReturn> | TRouteContextReturn | void
203
+ beforeLoad?: Constrain<
204
+ TBeforeLoadFn,
205
+ BeforeLoadFn<
206
+ TParentRoute,
207
+ TSearchValidator,
208
+ TParams,
209
+ TRouterContext,
210
+ TRouteContextFn
211
+ >
212
+ >
213
+
155
214
  loaderDeps?: (
156
- opts: FullSearchSchemaOption<
157
- ResolveFullSearchSchema<TParentRoute, TSearchValidator>
158
- >,
215
+ opts: FullSearchSchemaOption<TParentRoute, TSearchValidator>,
159
216
  ) => TLoaderDeps
217
+
160
218
  loader?: (
161
- ctx: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>,
219
+ ctx: LoaderFnContext<
220
+ TParentRoute,
221
+ TParams,
222
+ TLoaderDeps,
223
+ TRouterContext,
224
+ TRouteContextFn,
225
+ TBeforeLoadFn
226
+ >,
162
227
  ) => TLoaderDataReturn | Promise<TLoaderDataReturn>
163
- } & ParamsOptions<TPath, TParams>
228
+ }
164
229
 
165
230
  export type BaseRouteOptions<
166
231
  TParentRoute extends AnyRoute = AnyRoute,
@@ -168,37 +233,34 @@ export type BaseRouteOptions<
168
233
  TPath extends string = string,
169
234
  TSearchValidator extends AnySearchValidator = undefined,
170
235
  TParams = {},
171
- TAllParams = {},
172
- TRouteContextReturn = RouteContext,
173
- TParentAllContext = AnyContext,
174
- TAllContext = AnyContext,
175
236
  TLoaderDeps extends Record<string, any> = {},
176
237
  TLoaderDataReturn = {},
238
+ TRouterContext = {},
239
+ TRouteContextFn = AnyContext,
240
+ TBeforeLoadFn = AnyContext,
177
241
  > = RoutePathOptions<TCustomId, TPath> &
178
242
  FileBaseRouteOptions<
179
243
  TParentRoute,
180
244
  TPath,
181
245
  TSearchValidator,
182
246
  TParams,
183
- TAllParams,
184
- TRouteContextReturn,
185
- TParentAllContext,
186
- TAllContext,
187
247
  TLoaderDeps,
188
- TLoaderDataReturn
248
+ TLoaderDataReturn,
249
+ TRouterContext,
250
+ TRouteContextFn,
251
+ TBeforeLoadFn
189
252
  > & {
190
253
  getParentRoute: () => TParentRoute
191
254
  }
192
255
 
193
- export interface BeforeLoadContext<
194
- TFullSearchSchema,
195
- TAllParams,
196
- TParentAllContext,
197
- > extends FullSearchSchemaOption<TFullSearchSchema> {
256
+ export interface ContextOptions<
257
+ in out TParentRoute extends AnyRoute,
258
+ in out TSearchValidator extends AnySearchValidator,
259
+ in out TParams,
260
+ > extends FullSearchSchemaOption<TParentRoute, TSearchValidator> {
198
261
  abortController: AbortController
199
262
  preload: boolean
200
- params: Expand<TAllParams>
201
- context: TParentAllContext
263
+ params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>
202
264
  location: ParsedLocation
203
265
  /**
204
266
  * @deprecated Use `throw redirect({ to: '/somewhere' })` instead
@@ -208,15 +270,37 @@ export interface BeforeLoadContext<
208
270
  cause: 'preload' | 'enter' | 'stay'
209
271
  }
210
272
 
273
+ export interface RouteContextOptions<
274
+ in out TParentRoute extends AnyRoute,
275
+ in out TSearchValidator extends AnySearchValidator,
276
+ in out TParams,
277
+ in out TRouterContext,
278
+ > extends ContextOptions<TParentRoute, TSearchValidator, TParams> {
279
+ context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>
280
+ }
281
+
282
+ export interface BeforeLoadContextOptions<
283
+ in out TParentRoute extends AnyRoute,
284
+ in out TSearchValidator extends AnySearchValidator,
285
+ in out TParams,
286
+ in out TRouterContext,
287
+ in out TRouteContextFn,
288
+ > extends ContextOptions<TParentRoute, TSearchValidator, TParams> {
289
+ context: Expand<
290
+ BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>
291
+ >
292
+ }
293
+
211
294
  export type UpdatableRouteOptions<
212
295
  TParentRoute extends AnyRoute,
213
296
  TRouteId,
214
297
  TAllParams,
215
298
  TSearchValidator extends AnySearchValidator,
216
299
  TLoaderData,
217
- TAllContext,
218
- TRouteContext,
219
300
  TLoaderDeps,
301
+ TRouterContext,
302
+ TRouteContextFn,
303
+ TBeforeLoadFn,
220
304
  > = {
221
305
  // test?: (args: TAllContext) => void
222
306
  // If true, this route will be matched as case-sensitive
@@ -232,6 +316,7 @@ export type UpdatableRouteOptions<
232
316
  pendingMinMs?: number
233
317
  staleTime?: number
234
318
  gcTime?: number
319
+ preload?: boolean
235
320
  preloadStaleTime?: number
236
321
  preloadGcTime?: number
237
322
  // Filter functions that can manipulate search params *before* they are passed to links and navigate
@@ -254,8 +339,12 @@ export type UpdatableRouteOptions<
254
339
  TAllParams,
255
340
  ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
256
341
  TLoaderData,
257
- TAllContext,
258
- TRouteContext,
342
+ ResolveAllContext<
343
+ TParentRoute,
344
+ TRouterContext,
345
+ TRouteContextFn,
346
+ TBeforeLoadFn
347
+ >,
259
348
  TLoaderDeps
260
349
  >,
261
350
  ) => void
@@ -265,8 +354,12 @@ export type UpdatableRouteOptions<
265
354
  TAllParams,
266
355
  ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
267
356
  TLoaderData,
268
- TAllContext,
269
- TRouteContext,
357
+ ResolveAllContext<
358
+ TParentRoute,
359
+ TRouterContext,
360
+ TRouteContextFn,
361
+ TBeforeLoadFn
362
+ >,
270
363
  TLoaderDeps
271
364
  >,
272
365
  ) => void
@@ -276,8 +369,12 @@ export type UpdatableRouteOptions<
276
369
  TAllParams,
277
370
  ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
278
371
  TLoaderData,
279
- TAllContext,
280
- TRouteContext,
372
+ ResolveAllContext<
373
+ TParentRoute,
374
+ TRouterContext,
375
+ TRouteContextFn,
376
+ TBeforeLoadFn
377
+ >,
281
378
  TLoaderDeps
282
379
  >,
283
380
  ) => void
@@ -288,8 +385,12 @@ export type UpdatableRouteOptions<
288
385
  TAllParams,
289
386
  ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
290
387
  TLoaderData,
291
- TAllContext,
292
- TRouteContext,
388
+ ResolveAllContext<
389
+ TParentRoute,
390
+ TRouterContext,
391
+ TRouteContextFn,
392
+ TBeforeLoadFn
393
+ >,
293
394
  TLoaderDeps
294
395
  >
295
396
  >
@@ -298,8 +399,12 @@ export type UpdatableRouteOptions<
298
399
  TAllParams,
299
400
  ResolveFullSearchSchema<TParentRoute, TSearchValidator>,
300
401
  TLoaderData,
301
- TAllContext,
302
- TRouteContext,
402
+ ResolveAllContext<
403
+ TParentRoute,
404
+ TRouterContext,
405
+ TRouteContextFn,
406
+ TBeforeLoadFn
407
+ >,
303
408
  TLoaderDeps
304
409
  >
305
410
  params: TAllParams
@@ -372,24 +477,44 @@ export type DefaultSearchValidator = SearchValidator<
372
477
  >
373
478
 
374
479
  export type RouteLoaderFn<
375
- in out TAllParams = {},
376
- in out TLoaderDeps extends Record<string, any> = {},
377
- in out TAllContext = AnyContext,
480
+ in out TParentRoute extends AnyRoute = AnyRoute,
481
+ in out TParams = {},
482
+ in out TLoaderDeps = {},
483
+ in out TRouterContext = {},
484
+ in out TRouteContextFn = AnyContext,
485
+ in out TBeforeLoadFn = AnyContext,
378
486
  TLoaderData = undefined,
379
487
  > = (
380
- match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>,
488
+ match: LoaderFnContext<
489
+ TParentRoute,
490
+ TParams,
491
+ TLoaderDeps,
492
+ TRouterContext,
493
+ TRouteContextFn,
494
+ TBeforeLoadFn
495
+ >,
381
496
  ) => TLoaderData | Promise<TLoaderData>
382
497
 
383
498
  export interface LoaderFnContext<
384
- in out TAllParams = {},
499
+ in out TParentRoute extends AnyRoute = AnyRoute,
500
+ in out TParams = {},
385
501
  in out TLoaderDeps = {},
386
- in out TAllContext = AnyContext,
502
+ in out TRouterContext = {},
503
+ in out TRouteContextFn = AnyContext,
504
+ in out TBeforeLoadFn = AnyContext,
387
505
  > {
388
506
  abortController: AbortController
389
507
  preload: boolean
390
- params: Expand<TAllParams>
508
+ params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>
391
509
  deps: TLoaderDeps
392
- context: TAllContext
510
+ context: Expand<
511
+ ResolveAllContext<
512
+ TParentRoute,
513
+ TRouterContext,
514
+ TRouteContextFn,
515
+ TBeforeLoadFn
516
+ >
517
+ >
393
518
  location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps
394
519
  /**
395
520
  * @deprecated Use `throw redirect({ to: '/somewhere' })` instead
@@ -434,13 +559,15 @@ export type InferAllParams<TRoute> = TRoute extends {
434
559
  ? TAllParams
435
560
  : {}
436
561
 
437
- export type InferAllContext<TRoute> = TRoute extends {
438
- types: {
439
- allContext: infer TAllContext
440
- }
441
- }
442
- ? TAllContext
443
- : {}
562
+ export type InferAllContext<TRoute> = unknown extends TRoute
563
+ ? TRoute
564
+ : TRoute extends {
565
+ types: {
566
+ allContext: infer TAllContext
567
+ }
568
+ }
569
+ ? TAllContext
570
+ : {}
444
571
 
445
572
  export type ResolveSearchSchemaFnInput<
446
573
  TSearchValidator extends AnySearchValidator,
@@ -490,16 +617,61 @@ export type ResolveFullSearchSchemaInput<
490
617
  ResolveSearchSchemaInput<TSearchValidator>
491
618
  >
492
619
 
493
- export type ResolveRouteContext<TRouteContextReturn> = [
494
- TRouteContextReturn,
495
- ] extends [never]
496
- ? RouteContext
497
- : TRouteContextReturn
620
+ export type LooseReturnType<T> = T extends (
621
+ ...args: Array<any>
622
+ ) => infer TReturn
623
+ ? TReturn
624
+ : never
625
+
626
+ export type LooseAsyncReturnType<T> = T extends (
627
+ ...args: Array<any>
628
+ ) => infer TReturn
629
+ ? TReturn extends Promise<infer TReturn>
630
+ ? TReturn
631
+ : TReturn
632
+ : never
633
+
634
+ export type ContextReturnType<TContextFn> = unknown extends TContextFn
635
+ ? TContextFn
636
+ : LooseReturnType<TContextFn> extends never
637
+ ? AnyContext
638
+ : LooseReturnType<TContextFn>
639
+
640
+ export type ContextAsyncReturnType<TContextFn> = unknown extends TContextFn
641
+ ? TContextFn
642
+ : LooseAsyncReturnType<TContextFn> extends never
643
+ ? AnyContext
644
+ : LooseAsyncReturnType<TContextFn>
645
+
646
+ export type RouteContextParameter<
647
+ TParentRoute extends AnyRoute,
648
+ TRouterContext,
649
+ > = unknown extends TParentRoute
650
+ ? TRouterContext
651
+ : Assign<TRouterContext, InferAllContext<TParentRoute>>
652
+
653
+ export type ResolveRouteContext<TRouteContextFn, TBeforeLoadFn> = Assign<
654
+ ContextReturnType<TRouteContextFn>,
655
+ ContextAsyncReturnType<TBeforeLoadFn>
656
+ >
657
+ export type BeforeLoadContextParameter<
658
+ TParentRoute extends AnyRoute,
659
+ TRouterContext,
660
+ TRouteContextFn,
661
+ > = Assign<
662
+ RouteContextParameter<TParentRoute, TRouterContext>,
663
+ ContextReturnType<TRouteContextFn>
664
+ >
498
665
 
499
666
  export type ResolveAllContext<
500
667
  TParentRoute extends AnyRoute,
501
- TRouteContext,
502
- > = Assign<InferAllContext<TParentRoute>, TRouteContext>
668
+ TRouterContext,
669
+ TRouteContextFn,
670
+ TBeforeLoadFn,
671
+ > = Assign<
672
+ BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>,
673
+ ContextAsyncReturnType<TBeforeLoadFn>
674
+ >
503
675
 
504
676
  export type ResolveLoaderData<TLoaderDataReturn> = [TLoaderDataReturn] extends [
505
677
  never,
@@ -526,23 +698,9 @@ export interface AnyRoute
526
698
  any
527
699
  > {}
528
700
 
529
- export type AnyRouteWithContext<TContext> = Route<
530
- any,
531
- any,
532
- any,
533
- any,
534
- any,
535
- any,
536
- any,
537
- any,
538
- any,
539
- any,
540
- any,
541
- any,
542
- TContext,
543
- any,
544
- any
545
- >
701
+ export type AnyRouteWithContext<TContext> = AnyRoute & {
702
+ types: { allContext: TContext }
703
+ }
546
704
 
547
705
  export type ResolveAllParamsFromParent<
548
706
  TParentRoute extends AnyRoute,
@@ -674,11 +832,11 @@ export class Route<
674
832
  TPath
675
833
  >,
676
834
  in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
677
- in out TParams = Record<ParsePathParams<TPath>, string>,
835
+ in out TParams = ResolveParams<TPath>,
678
836
  in out TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
679
- TRouteContextReturn = RouteContext,
680
- in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
681
- in out TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,
837
+ in out TRouterContext = AnyContext,
838
+ in out TRouteContextFn = AnyContext,
839
+ in out TBeforeLoadFn = AnyContext,
682
840
  in out TLoaderDeps extends Record<string, any> = {},
683
841
  TLoaderDataReturn = {},
684
842
  in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
@@ -692,13 +850,12 @@ export class Route<
692
850
  TSearchValidator,
693
851
  TParams,
694
852
  TAllParams,
695
- TRouteContextReturn,
696
- TRouteContext,
697
- InferAllContext<TParentRoute>,
698
- TAllContext,
699
853
  TLoaderDeps,
700
854
  TLoaderDataReturn,
701
- TLoaderData
855
+ TLoaderData,
856
+ TRouterContext,
857
+ TRouteContextFn,
858
+ TBeforeLoadFn
702
859
  >
703
860
 
704
861
  // Set up in this.init()
@@ -728,13 +885,12 @@ export class Route<
728
885
  TSearchValidator,
729
886
  TParams,
730
887
  TAllParams,
731
- TRouteContextReturn,
732
- TRouteContext,
733
- InferAllContext<TParentRoute>,
734
- TAllContext,
735
888
  TLoaderDeps,
736
889
  TLoaderDataReturn,
737
- TLoaderData
890
+ TLoaderData,
891
+ TRouterContext,
892
+ TRouteContextFn,
893
+ TBeforeLoadFn
738
894
  >,
739
895
  ) {
740
896
  this.options = (options as any) || {}
@@ -764,8 +920,16 @@ export class Route<
764
920
  >
765
921
  params: TParams
766
922
  allParams: TAllParams
767
- routeContext: TRouteContext
768
- allContext: TAllContext
923
+ routerContext: TRouterContext
924
+ routeContext: ResolveRouteContext<TRouteContextFn, TBeforeLoadFn>
925
+ routeContextFn: TRouteContextFn
926
+ beforeLoadFn: TBeforeLoadFn
927
+ allContext: ResolveAllContext<
928
+ TParentRoute,
929
+ TRouterContext,
930
+ TRouteContextFn,
931
+ TBeforeLoadFn
932
+ >
769
933
  children: TChildren
770
934
  loaderData: TLoaderData
771
935
  loaderDeps: TLoaderDeps
@@ -782,13 +946,12 @@ export class Route<
782
946
  TSearchValidator,
783
947
  TParams,
784
948
  TAllParams,
785
- TRouteContextReturn,
786
- TRouteContext,
787
- InferAllContext<TParentRoute>,
788
- TAllContext,
789
949
  TLoaderDeps,
790
950
  TLoaderDataReturn,
791
- TLoaderData
951
+ TLoaderData,
952
+ TRouterContext,
953
+ TRouteContextFn,
954
+ TBeforeLoadFn
792
955
  > &
793
956
  RoutePathOptionsIntersection<TCustomId, TPath>)
794
957
  | undefined
@@ -796,7 +959,7 @@ export class Route<
796
959
  const isRoot = !options?.path && !options?.id
797
960
 
798
961
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
799
- this.parentRoute = this.options?.getParentRoute?.()
962
+ this.parentRoute = this.options.getParentRoute?.()
800
963
 
801
964
  if (isRoot) {
802
965
  this.path = rootRouteId as TPath
@@ -857,9 +1020,9 @@ export class Route<
857
1020
  TSearchValidator,
858
1021
  TParams,
859
1022
  TAllParams,
860
- TRouteContextReturn,
861
- TRouteContext,
862
- TAllContext,
1023
+ TRouterContext,
1024
+ TRouteContextFn,
1025
+ TBeforeLoadFn,
863
1026
  TLoaderDeps,
864
1027
  TLoaderDataReturn,
865
1028
  TLoaderData,
@@ -872,7 +1035,15 @@ export class Route<
872
1035
  }
873
1036
 
874
1037
  updateLoader = <TNewLoaderData = unknown>(options: {
875
- loader: RouteLoaderFn<TAllParams, TLoaderDeps, TAllContext, TNewLoaderData>
1038
+ loader: RouteLoaderFn<
1039
+ TParentRoute,
1040
+ TParams,
1041
+ TLoaderDeps,
1042
+ TRouterContext,
1043
+ TRouteContextFn,
1044
+ TBeforeLoadFn,
1045
+ TNewLoaderData
1046
+ >
876
1047
  }) => {
877
1048
  Object.assign(this.options, options)
878
1049
  return this as unknown as Route<
@@ -884,9 +1055,9 @@ export class Route<
884
1055
  TSearchValidator,
885
1056
  TParams,
886
1057
  TAllParams,
887
- TRouteContextReturn,
888
- TRouteContext,
889
- TAllContext,
1058
+ TRouterContext,
1059
+ TRouteContextFn,
1060
+ TBeforeLoadFn,
890
1061
  TLoaderDeps,
891
1062
  TNewLoaderData,
892
1063
  TChildren
@@ -900,9 +1071,10 @@ export class Route<
900
1071
  TAllParams,
901
1072
  TSearchValidator,
902
1073
  TLoaderData,
903
- TAllContext,
904
- TRouteContext,
905
- TLoaderDeps
1074
+ TLoaderDeps,
1075
+ TRouterContext,
1076
+ TRouteContextFn,
1077
+ TBeforeLoadFn
906
1078
  >,
907
1079
  ): this => {
908
1080
  Object.assign(this.options, options)
@@ -925,8 +1097,26 @@ export class Route<
925
1097
  return useMatch({ ...opts, from: this.id })
926
1098
  }
927
1099
 
928
- useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {
929
- select?: (search: Expand<TAllContext>) => TSelected
1100
+ useRouteContext = <
1101
+ TSelected = Expand<
1102
+ ResolveAllContext<
1103
+ TParentRoute,
1104
+ TRouterContext,
1105
+ TRouteContextFn,
1106
+ TBeforeLoadFn
1107
+ >
1108
+ >,
1109
+ >(opts?: {
1110
+ select?: (
1111
+ search: Expand<
1112
+ ResolveAllContext<
1113
+ TParentRoute,
1114
+ TRouterContext,
1115
+ TRouteContextFn,
1116
+ TBeforeLoadFn
1117
+ >
1118
+ >,
1119
+ ) => TSelected
930
1120
  }): TSelected => {
931
1121
  return useMatch({
932
1122
  ...opts,
@@ -982,11 +1172,10 @@ export function createRoute<
982
1172
  TPath
983
1173
  >,
984
1174
  TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
985
- TParams = Record<ParsePathParams<TPath>, string>,
1175
+ TParams = ResolveParams<TPath>,
986
1176
  TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
987
- TRouteContextReturn = RouteContext,
988
- TRouteContext = ResolveRouteContext<TRouteContextReturn>,
989
- TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,
1177
+ TRouteContextFn = AnyContext,
1178
+ TBeforeLoadFn = AnyContext,
990
1179
  TLoaderDeps extends Record<string, any> = {},
991
1180
  TLoaderDataReturn = {},
992
1181
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
@@ -999,13 +1188,12 @@ export function createRoute<
999
1188
  TSearchValidator,
1000
1189
  TParams,
1001
1190
  TAllParams,
1002
- TRouteContextReturn,
1003
- TRouteContext,
1004
- InferAllContext<TParentRoute>,
1005
- TAllContext,
1006
1191
  TLoaderDeps,
1007
1192
  TLoaderDataReturn,
1008
- TLoaderData
1193
+ TLoaderData,
1194
+ AnyContext,
1195
+ TRouteContextFn,
1196
+ TBeforeLoadFn
1009
1197
  >,
1010
1198
  ) {
1011
1199
  return new Route<
@@ -1017,9 +1205,9 @@ export function createRoute<
1017
1205
  TSearchValidator,
1018
1206
  TParams,
1019
1207
  TAllParams,
1020
- TRouteContextReturn,
1021
- TRouteContext,
1022
- TAllContext,
1208
+ AnyContext,
1209
+ TRouteContextFn,
1210
+ TBeforeLoadFn,
1023
1211
  TLoaderDeps,
1024
1212
  TLoaderDataReturn,
1025
1213
  TLoaderData,
@@ -1031,9 +1219,9 @@ export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
1031
1219
 
1032
1220
  export type RootRouteOptions<
1033
1221
  TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
1034
- TRouteContextReturn = RouteContext,
1035
- TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1036
1222
  TRouterContext = {},
1223
+ TRouteContextFn = AnyContext,
1224
+ TBeforeLoadFn = AnyContext,
1037
1225
  TLoaderDeps extends Record<string, any> = {},
1038
1226
  TLoaderDataReturn = {},
1039
1227
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
@@ -1045,13 +1233,12 @@ export type RootRouteOptions<
1045
1233
  TSearchValidator,
1046
1234
  {}, // TParams
1047
1235
  {}, // TAllParams
1048
- TRouteContextReturn, // TRouteContextReturn
1049
- TRouteContext, // TRouteContext
1050
- TRouterContext, // TParentAllContext
1051
- Assign<TRouterContext, TRouteContext>, // TAllContext
1052
1236
  TLoaderDeps,
1053
1237
  TLoaderDataReturn, // TLoaderDataReturn,
1054
- TLoaderData // TLoaderData,
1238
+ TLoaderData, // TLoaderData,
1239
+ TRouterContext,
1240
+ TRouteContextFn,
1241
+ TBeforeLoadFn
1055
1242
  >,
1056
1243
  | 'path'
1057
1244
  | 'id'
@@ -1064,19 +1251,18 @@ export type RootRouteOptions<
1064
1251
 
1065
1252
  export function createRootRouteWithContext<TRouterContext extends {}>() {
1066
1253
  return <
1254
+ TRouteContextFn = AnyContext,
1255
+ TBeforeLoadFn = AnyContext,
1067
1256
  TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
1068
- TRouteContextReturn extends RouteContext = RouteContext,
1069
- TRouteContext extends
1070
- RouteContext = ResolveRouteContext<TRouteContextReturn>,
1071
1257
  TLoaderDeps extends Record<string, any> = {},
1072
1258
  TLoaderDataReturn = {},
1073
1259
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
1074
1260
  >(
1075
1261
  options?: RootRouteOptions<
1076
1262
  TSearchValidator,
1077
- TRouteContextReturn,
1078
- TRouteContext,
1079
1263
  TRouterContext,
1264
+ TRouteContextFn,
1265
+ TBeforeLoadFn,
1080
1266
  TLoaderDeps,
1081
1267
  TLoaderDataReturn,
1082
1268
  TLoaderData
@@ -1084,9 +1270,9 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
1084
1270
  ) => {
1085
1271
  return createRootRoute<
1086
1272
  TSearchValidator,
1087
- TRouteContextReturn,
1088
- TRouteContext,
1089
1273
  TRouterContext,
1274
+ TRouteContextFn,
1275
+ TBeforeLoadFn,
1090
1276
  TLoaderDeps,
1091
1277
  TLoaderData
1092
1278
  >(options as any)
@@ -1100,9 +1286,9 @@ export const rootRouteWithContext = createRootRouteWithContext
1100
1286
 
1101
1287
  export class RootRoute<
1102
1288
  in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
1103
- TRouteContextReturn = RouteContext,
1104
- in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1105
1289
  in out TRouterContext = {},
1290
+ in out TRouteContextFn = AnyContext,
1291
+ in out TBeforeLoadFn = AnyContext,
1106
1292
  TLoaderDeps extends Record<string, any> = {},
1107
1293
  TLoaderDataReturn = {},
1108
1294
  in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
@@ -1116,9 +1302,9 @@ export class RootRoute<
1116
1302
  TSearchValidator, // TSearchValidator
1117
1303
  {}, // TParams
1118
1304
  {}, // TAllParams
1119
- TRouteContextReturn, // TRouteContextReturn
1120
- TRouteContext, // TRouteContext
1121
- Assign<TRouterContext, TRouteContext>, // TAllContext
1305
+ TRouterContext,
1306
+ TRouteContextFn,
1307
+ TBeforeLoadFn,
1122
1308
  TLoaderDeps,
1123
1309
  TLoaderDataReturn,
1124
1310
  TLoaderData,
@@ -1130,9 +1316,9 @@ export class RootRoute<
1130
1316
  constructor(
1131
1317
  options?: RootRouteOptions<
1132
1318
  TSearchValidator,
1133
- TRouteContextReturn,
1134
- TRouteContext,
1135
1319
  TRouterContext,
1320
+ TRouteContextFn,
1321
+ TBeforeLoadFn,
1136
1322
  TLoaderDeps,
1137
1323
  TLoaderDataReturn,
1138
1324
  TLoaderData
@@ -1149,9 +1335,9 @@ export class RootRoute<
1149
1335
  children: TNewChildren,
1150
1336
  ): RootRoute<
1151
1337
  TSearchValidator,
1152
- TRouteContextReturn,
1153
- TRouteContext,
1154
1338
  TRouterContext,
1339
+ TRouteContextFn,
1340
+ TBeforeLoadFn,
1155
1341
  TLoaderDeps,
1156
1342
  TLoaderDataReturn,
1157
1343
  TLoaderData,
@@ -1163,18 +1349,18 @@ export class RootRoute<
1163
1349
 
1164
1350
  export function createRootRoute<
1165
1351
  TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
1166
- TRouteContextReturn = RouteContext,
1167
- TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1168
1352
  TRouterContext = {},
1353
+ TRouteContextFn = AnyContext,
1354
+ TBeforeLoadFn = AnyContext,
1169
1355
  TLoaderDeps extends Record<string, any> = {},
1170
1356
  TLoaderDataReturn = {},
1171
1357
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
1172
1358
  >(
1173
1359
  options?: RootRouteOptions<
1174
1360
  TSearchValidator,
1175
- TRouteContextReturn,
1176
- TRouteContext,
1177
1361
  TRouterContext,
1362
+ TRouteContextFn,
1363
+ TBeforeLoadFn,
1178
1364
  TLoaderDeps,
1179
1365
  TLoaderDataReturn,
1180
1366
  TLoaderData
@@ -1182,9 +1368,9 @@ export function createRootRoute<
1182
1368
  ) {
1183
1369
  return new RootRoute<
1184
1370
  TSearchValidator,
1185
- TRouteContextReturn,
1186
- TRouteContext,
1187
1371
  TRouterContext,
1372
+ TRouteContextFn,
1373
+ TBeforeLoadFn,
1188
1374
  TLoaderDeps,
1189
1375
  TLoaderDataReturn,
1190
1376
  TLoaderData
@@ -1289,10 +1475,10 @@ export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>
1289
1475
 
1290
1476
  export class NotFoundRoute<
1291
1477
  TParentRoute extends AnyRootRoute,
1478
+ TRouterContext = AnyContext,
1479
+ TRouteContextFn = AnyContext,
1480
+ TBeforeLoadFn = AnyContext,
1292
1481
  TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
1293
- TRouteContextReturn = AnyContext,
1294
- TRouteContext = RouteContext,
1295
- TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,
1296
1482
  TLoaderDeps extends Record<string, any> = {},
1297
1483
  TLoaderDataReturn = {},
1298
1484
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
@@ -1306,9 +1492,9 @@ export class NotFoundRoute<
1306
1492
  TSearchValidator,
1307
1493
  {},
1308
1494
  {},
1309
- TRouteContextReturn,
1310
- TRouteContext,
1311
- TAllContext,
1495
+ TRouterContext,
1496
+ TRouteContextFn,
1497
+ TBeforeLoadFn,
1312
1498
  TLoaderDeps,
1313
1499
  TLoaderDataReturn,
1314
1500
  TLoaderData,
@@ -1323,13 +1509,12 @@ export class NotFoundRoute<
1323
1509
  TSearchValidator,
1324
1510
  {},
1325
1511
  {},
1326
- TRouteContextReturn,
1327
- TRouteContext,
1328
- InferAllContext<TParentRoute>,
1329
- TAllContext,
1330
1512
  TLoaderDeps,
1331
1513
  TLoaderDataReturn,
1332
- TLoaderData
1514
+ TLoaderData,
1515
+ TRouterContext,
1516
+ TRouteContextFn,
1517
+ TBeforeLoadFn
1333
1518
  >,
1334
1519
  | 'caseSensitive'
1335
1520
  | 'parseParams'