@tanstack/react-router 1.27.0 → 1.28.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.cjs +45 -23
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +5 -6
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +13 -14
- package/dist/cjs/index.cjs +0 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +34 -24
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +3 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +44 -47
- package/dist/cjs/routeInfo.d.cts +5 -7
- package/dist/cjs/router.cjs +374 -327
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -3
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/utils.cjs +20 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +11 -4
- package/dist/esm/Matches.d.ts +5 -6
- package/dist/esm/Matches.js +46 -24
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +13 -14
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/link.d.ts +34 -24
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirects.d.ts +3 -1
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +44 -47
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +5 -7
- package/dist/esm/router.d.ts +3 -3
- package/dist/esm/router.js +375 -328
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/utils.d.ts +11 -4
- package/dist/esm/utils.js +20 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +4 -2
- package/src/Matches.tsx +75 -37
- package/src/fileRoute.ts +17 -36
- package/src/index.tsx +0 -2
- package/src/link.tsx +189 -82
- package/src/redirects.ts +4 -2
- package/src/route.ts +149 -187
- package/src/routeInfo.ts +5 -7
- package/src/router.ts +501 -429
- package/src/useParams.tsx +2 -2
- package/src/utils.ts +41 -8
package/src/route.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { useParams } from './useParams'
|
|
|
5
5
|
import { useSearch } from './useSearch'
|
|
6
6
|
import { notFound } from './not-found'
|
|
7
7
|
import { useNavigate } from './useNavigate'
|
|
8
|
+
import type { UseNavigateResult } from './useNavigate'
|
|
8
9
|
import type * as React from 'react'
|
|
9
10
|
import type { RouteMatch } from './Matches'
|
|
10
11
|
import type { AnyRouteMatch } from './Matches'
|
|
@@ -59,13 +60,13 @@ export type RouteOptions<
|
|
|
59
60
|
TPath extends string = string,
|
|
60
61
|
TSearchSchemaInput extends Record<string, any> = {},
|
|
61
62
|
TSearchSchema extends Record<string, any> = {},
|
|
62
|
-
TSearchSchemaUsed
|
|
63
|
-
TFullSearchSchemaInput
|
|
63
|
+
TSearchSchemaUsed = {},
|
|
64
|
+
TFullSearchSchemaInput = TSearchSchemaUsed,
|
|
64
65
|
TFullSearchSchema = TSearchSchema,
|
|
65
|
-
TParams
|
|
66
|
-
TAllParams
|
|
66
|
+
TParams = AnyPathParams,
|
|
67
|
+
TAllParams = TParams,
|
|
67
68
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
68
|
-
TRouteContext
|
|
69
|
+
TRouteContext = RouteContext,
|
|
69
70
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
70
71
|
TAllContext = AnyContext,
|
|
71
72
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -108,10 +109,10 @@ export type FileBaseRouteOptions<
|
|
|
108
109
|
TSearchSchemaInput extends Record<string, any> = {},
|
|
109
110
|
TSearchSchema extends Record<string, any> = {},
|
|
110
111
|
TFullSearchSchema = TSearchSchema,
|
|
111
|
-
TParams
|
|
112
|
+
TParams = {},
|
|
112
113
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
113
114
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
114
|
-
TRouteContext
|
|
115
|
+
TRouteContext = RouteContext,
|
|
115
116
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
116
117
|
TAllContext = AnyContext,
|
|
117
118
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -171,13 +172,13 @@ export type BaseRouteOptions<
|
|
|
171
172
|
TPath extends string = string,
|
|
172
173
|
TSearchSchemaInput extends Record<string, any> = {},
|
|
173
174
|
TSearchSchema extends Record<string, any> = {},
|
|
174
|
-
TSearchSchemaUsed
|
|
175
|
-
TFullSearchSchemaInput
|
|
175
|
+
TSearchSchemaUsed = {},
|
|
176
|
+
TFullSearchSchemaInput = TSearchSchemaUsed,
|
|
176
177
|
TFullSearchSchema = TSearchSchema,
|
|
177
|
-
TParams
|
|
178
|
+
TParams = {},
|
|
178
179
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
179
180
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
180
|
-
TRouteContext
|
|
181
|
+
TRouteContext = RouteContext,
|
|
181
182
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
182
183
|
TAllContext = AnyContext,
|
|
183
184
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -202,12 +203,12 @@ export type BaseRouteOptions<
|
|
|
202
203
|
}
|
|
203
204
|
|
|
204
205
|
type BeforeLoadFn<
|
|
205
|
-
TFullSearchSchema,
|
|
206
|
-
TParentRoute extends AnyRoute,
|
|
207
|
-
TAllParams,
|
|
206
|
+
in out TFullSearchSchema,
|
|
207
|
+
in out TParentRoute extends AnyRoute,
|
|
208
|
+
in out TAllParams,
|
|
208
209
|
TRouteContextReturn extends RouteContext,
|
|
209
|
-
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
210
|
-
TContext = IsAny<TParentRoute['types']['allContext'], TRouterContext>,
|
|
210
|
+
in out TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
211
|
+
in out TContext = IsAny<TParentRoute['types']['allContext'], TRouterContext>,
|
|
211
212
|
> = (opts: {
|
|
212
213
|
search: TFullSearchSchema
|
|
213
214
|
abortController: AbortController
|
|
@@ -220,51 +221,44 @@ type BeforeLoadFn<
|
|
|
220
221
|
cause: 'preload' | 'enter' | 'stay'
|
|
221
222
|
}) => Promise<TRouteContextReturn> | TRouteContextReturn | void
|
|
222
223
|
|
|
223
|
-
export type UpdatableRouteOptions<
|
|
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
|
-
| Promise<Array<JSX.IntrinsicElements['meta']>>
|
|
262
|
-
links?: () => Array<JSX.IntrinsicElements['link']>
|
|
263
|
-
scripts?: () => Array<JSX.IntrinsicElements['script']>
|
|
264
|
-
headers?: (ctx: {
|
|
265
|
-
loaderData: TLoaderData
|
|
266
|
-
}) => Promise<Record<string, string>> | Record<string, string>
|
|
267
|
-
} & UpdatableStaticRouteOption
|
|
224
|
+
export type UpdatableRouteOptions<TAllParams, TFullSearchSchema, TLoaderData> =
|
|
225
|
+
{
|
|
226
|
+
// test?: (args: TAllContext) => void
|
|
227
|
+
// If true, this route will be matched as case-sensitive
|
|
228
|
+
caseSensitive?: boolean
|
|
229
|
+
// If true, this route will be forcefully wrapped in a suspense boundary
|
|
230
|
+
wrapInSuspense?: boolean
|
|
231
|
+
// The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
|
|
232
|
+
component?: RouteComponent
|
|
233
|
+
errorComponent?: false | null | ErrorRouteComponent
|
|
234
|
+
notFoundComponent?: NotFoundRouteComponent
|
|
235
|
+
pendingComponent?: RouteComponent
|
|
236
|
+
pendingMs?: number
|
|
237
|
+
pendingMinMs?: number
|
|
238
|
+
staleTime?: number
|
|
239
|
+
gcTime?: number
|
|
240
|
+
preloadStaleTime?: number
|
|
241
|
+
preloadGcTime?: number
|
|
242
|
+
// Filter functions that can manipulate search params *before* they are passed to links and navigate
|
|
243
|
+
// calls that match this route.
|
|
244
|
+
preSearchFilters?: Array<SearchFilter<TFullSearchSchema>>
|
|
245
|
+
// Filter functions that can manipulate search params *after* they are passed to links and navigate
|
|
246
|
+
// calls that match this route.
|
|
247
|
+
postSearchFilters?: Array<SearchFilter<TFullSearchSchema>>
|
|
248
|
+
onError?: (err: any) => void
|
|
249
|
+
// These functions are called as route matches are loaded, stick around and leave the active
|
|
250
|
+
// matches
|
|
251
|
+
onEnter?: (match: AnyRouteMatch) => void
|
|
252
|
+
onStay?: (match: AnyRouteMatch) => void
|
|
253
|
+
onLeave?: (match: AnyRouteMatch) => void
|
|
254
|
+
meta?: (ctx: {
|
|
255
|
+
params: TAllParams
|
|
256
|
+
loaderData: TLoaderData
|
|
257
|
+
}) => Array<JSX.IntrinsicElements['meta']>
|
|
258
|
+
links?: () => Array<JSX.IntrinsicElements['link']>
|
|
259
|
+
scripts?: () => Array<JSX.IntrinsicElements['script']>
|
|
260
|
+
headers?: (ctx: { loaderData: TLoaderData }) => Record<string, string>
|
|
261
|
+
} & UpdatableStaticRouteOption
|
|
268
262
|
|
|
269
263
|
export type UpdatableStaticRouteOption =
|
|
270
264
|
{} extends PickRequired<StaticDataRouteOption>
|
|
@@ -323,26 +317,26 @@ export type SearchSchemaValidatorFn<TInput, TReturn> = (
|
|
|
323
317
|
) => TReturn
|
|
324
318
|
|
|
325
319
|
export type RouteLoaderFn<
|
|
326
|
-
TAllParams = {},
|
|
327
|
-
TLoaderDeps extends Record<string, any> = {},
|
|
328
|
-
TAllContext = AnyContext,
|
|
329
|
-
|
|
320
|
+
in out TAllParams = {},
|
|
321
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
322
|
+
in out TAllContext = AnyContext,
|
|
323
|
+
in out TRouteContext = AnyContext,
|
|
330
324
|
TLoaderData = unknown,
|
|
331
325
|
> = (
|
|
332
326
|
match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,
|
|
333
327
|
) => Promise<TLoaderData> | TLoaderData
|
|
334
328
|
|
|
335
329
|
export interface LoaderFnContext<
|
|
336
|
-
TAllParams = {},
|
|
337
|
-
TLoaderDeps = {},
|
|
338
|
-
TAllContext = AnyContext,
|
|
339
|
-
|
|
330
|
+
in out TAllParams = {},
|
|
331
|
+
in out TLoaderDeps = {},
|
|
332
|
+
in out TAllContext = AnyContext,
|
|
333
|
+
in out TRouteContext = AnyContext,
|
|
340
334
|
> {
|
|
341
335
|
abortController: AbortController
|
|
342
336
|
preload: boolean
|
|
343
337
|
params: TAllParams
|
|
344
338
|
deps: TLoaderDeps
|
|
345
|
-
context:
|
|
339
|
+
context: Assign<TAllContext, TRouteContext>
|
|
346
340
|
location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps
|
|
347
341
|
/**
|
|
348
342
|
* @deprecated Use `throw redirect({ to: '/somewhere' })` instead
|
|
@@ -382,25 +376,21 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
|
|
|
382
376
|
export type ResolveFullSearchSchema<
|
|
383
377
|
TParentRoute extends AnyRoute,
|
|
384
378
|
TSearchSchema,
|
|
385
|
-
> =
|
|
386
|
-
|
|
387
|
-
TParentRoute['
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
TSearchSchema
|
|
391
|
-
>
|
|
379
|
+
> = Assign<
|
|
380
|
+
TParentRoute['id'] extends RootRouteId
|
|
381
|
+
? Omit<TParentRoute['types']['searchSchema'], keyof RootSearchSchema>
|
|
382
|
+
: TParentRoute['types']['fullSearchSchema'],
|
|
383
|
+
TSearchSchema
|
|
392
384
|
>
|
|
393
385
|
|
|
394
386
|
export type ResolveFullSearchSchemaInput<
|
|
395
387
|
TParentRoute extends AnyRoute,
|
|
396
388
|
TSearchSchemaUsed,
|
|
397
|
-
> =
|
|
398
|
-
|
|
399
|
-
TParentRoute['
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
TSearchSchemaUsed
|
|
403
|
-
>
|
|
389
|
+
> = Assign<
|
|
390
|
+
TParentRoute['id'] extends RootRouteId
|
|
391
|
+
? Omit<TParentRoute['types']['searchSchemaInput'], keyof RootSearchSchema>
|
|
392
|
+
: TParentRoute['types']['fullSearchSchemaInput'],
|
|
393
|
+
TSearchSchemaUsed
|
|
404
394
|
>
|
|
405
395
|
|
|
406
396
|
export interface AnyRoute
|
|
@@ -424,22 +414,16 @@ export interface AnyRoute
|
|
|
424
414
|
any,
|
|
425
415
|
any,
|
|
426
416
|
any,
|
|
427
|
-
any,
|
|
428
417
|
any
|
|
429
418
|
> {}
|
|
430
419
|
|
|
431
420
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
432
421
|
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>
|
|
433
422
|
|
|
434
|
-
export type ResolveAllParams<
|
|
435
|
-
TParentRoute extends AnyRoute,
|
|
436
|
-
TParams extends AnyPathParams,
|
|
437
|
-
> =
|
|
423
|
+
export type ResolveAllParams<TParentRoute extends AnyRoute, TParams> =
|
|
438
424
|
Record<never, string> extends TParentRoute['types']['allParams']
|
|
439
425
|
? TParams
|
|
440
|
-
:
|
|
441
|
-
UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}
|
|
442
|
-
>
|
|
426
|
+
: UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}
|
|
443
427
|
|
|
444
428
|
export type RouteConstraints = {
|
|
445
429
|
TParentRoute: AnyRoute
|
|
@@ -463,9 +447,9 @@ export function getRouteApi<
|
|
|
463
447
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
464
448
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
465
449
|
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
|
|
466
|
-
TAllParams
|
|
450
|
+
TAllParams = TRoute['types']['allParams'],
|
|
467
451
|
TAllContext = TRoute['types']['allContext'],
|
|
468
|
-
TLoaderDeps
|
|
452
|
+
TLoaderDeps = TRoute['types']['loaderDeps'],
|
|
469
453
|
TLoaderData = TRoute['types']['loaderData'],
|
|
470
454
|
>(id: TId) {
|
|
471
455
|
return new RouteApi<
|
|
@@ -483,9 +467,9 @@ export class RouteApi<
|
|
|
483
467
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
484
468
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
485
469
|
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
|
|
486
|
-
TAllParams
|
|
470
|
+
TAllParams = TRoute['types']['allParams'],
|
|
487
471
|
TAllContext = TRoute['types']['allContext'],
|
|
488
|
-
TLoaderDeps
|
|
472
|
+
TLoaderDeps = TRoute['types']['loaderDeps'],
|
|
489
473
|
TLoaderData = TRoute['types']['loaderData'],
|
|
490
474
|
> {
|
|
491
475
|
id: TId
|
|
@@ -507,8 +491,8 @@ export class RouteApi<
|
|
|
507
491
|
return useMatch({ select: opts?.select, from: this.id })
|
|
508
492
|
}
|
|
509
493
|
|
|
510
|
-
useRouteContext = <TSelected = TAllContext
|
|
511
|
-
select?: (s: TAllContext) => TSelected
|
|
494
|
+
useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {
|
|
495
|
+
select?: (s: Expand<TAllContext>) => TSelected
|
|
512
496
|
}): TSelected => {
|
|
513
497
|
return useMatch({
|
|
514
498
|
from: this.id,
|
|
@@ -516,14 +500,14 @@ export class RouteApi<
|
|
|
516
500
|
})
|
|
517
501
|
}
|
|
518
502
|
|
|
519
|
-
useSearch = <TSelected = TFullSearchSchema
|
|
520
|
-
select?: (s: TFullSearchSchema) => TSelected
|
|
503
|
+
useSearch = <TSelected = Expand<TFullSearchSchema>>(opts?: {
|
|
504
|
+
select?: (s: Expand<TFullSearchSchema>) => TSelected
|
|
521
505
|
}): TSelected => {
|
|
522
506
|
return useSearch({ ...opts, from: this.id })
|
|
523
507
|
}
|
|
524
508
|
|
|
525
|
-
useParams = <TSelected = TAllParams
|
|
526
|
-
select?: (s: TAllParams) => TSelected
|
|
509
|
+
useParams = <TSelected = Expand<TAllParams>>(opts?: {
|
|
510
|
+
select?: (s: Expand<TAllParams>) => TSelected
|
|
527
511
|
}): TSelected => {
|
|
528
512
|
return useParams({ ...opts, from: this.id })
|
|
529
513
|
}
|
|
@@ -550,55 +534,48 @@ export class RouteApi<
|
|
|
550
534
|
}
|
|
551
535
|
|
|
552
536
|
export class Route<
|
|
553
|
-
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
537
|
+
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
554
538
|
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
555
|
-
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
539
|
+
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
556
540
|
TParentRoute,
|
|
557
541
|
TPath
|
|
558
542
|
>,
|
|
559
|
-
TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
560
|
-
TId extends RouteConstraints['TId'] = ResolveId<
|
|
543
|
+
in out TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
544
|
+
in out TId extends RouteConstraints['TId'] = ResolveId<
|
|
561
545
|
TParentRoute,
|
|
562
546
|
TCustomId,
|
|
563
547
|
TPath
|
|
564
548
|
>,
|
|
565
|
-
TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
|
|
566
|
-
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
567
|
-
TSearchSchemaUsed extends
|
|
568
|
-
string,
|
|
569
|
-
any
|
|
570
|
-
> = TSearchSchemaInput extends SearchSchemaInput
|
|
549
|
+
in out TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
|
|
550
|
+
in out TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
551
|
+
in out TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
|
|
571
552
|
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
|
|
572
553
|
: TSearchSchema,
|
|
573
|
-
TFullSearchSchemaInput
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
|
|
577
|
-
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
578
|
-
TParams extends RouteConstraints['TParams'] = Expand<
|
|
579
|
-
Record<ParsePathParams<TPath>, string>
|
|
554
|
+
in out TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
555
|
+
TParentRoute,
|
|
556
|
+
TSearchSchemaUsed
|
|
580
557
|
>,
|
|
581
|
-
|
|
558
|
+
in out TFullSearchSchema = ResolveFullSearchSchema<
|
|
582
559
|
TParentRoute,
|
|
583
|
-
|
|
560
|
+
TSearchSchema
|
|
584
561
|
>,
|
|
562
|
+
in out TParams = Record<ParsePathParams<TPath>, string>,
|
|
563
|
+
in out TAllParams = ResolveAllParams<TParentRoute, TParams>,
|
|
585
564
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
586
|
-
in out TRouteContext
|
|
587
|
-
TRouteContextReturn,
|
|
588
|
-
] extends [never]
|
|
565
|
+
in out TRouteContext = [TRouteContextReturn] extends [never]
|
|
589
566
|
? RouteContext
|
|
590
567
|
: TRouteContextReturn,
|
|
591
|
-
in out TAllContext =
|
|
592
|
-
|
|
568
|
+
in out TAllContext = Assign<
|
|
569
|
+
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
570
|
+
TRouteContext
|
|
593
571
|
>,
|
|
594
|
-
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
595
|
-
TLoaderDeps extends Record<string, any> = {},
|
|
572
|
+
in out TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
573
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
596
574
|
TLoaderDataReturn = unknown,
|
|
597
|
-
TLoaderData = [TLoaderDataReturn] extends [never]
|
|
575
|
+
in out TLoaderData = [TLoaderDataReturn] extends [never]
|
|
598
576
|
? undefined
|
|
599
577
|
: TLoaderDataReturn,
|
|
600
|
-
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
601
|
-
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
578
|
+
in out TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
602
579
|
> {
|
|
603
580
|
isRoot: TParentRoute extends Route<any> ? true : false
|
|
604
581
|
options: RouteOptions<
|
|
@@ -687,13 +664,12 @@ export class Route<
|
|
|
687
664
|
routeContext: TRouteContext
|
|
688
665
|
allContext: TAllContext
|
|
689
666
|
children: TChildren
|
|
690
|
-
routeTree: TRouteTree
|
|
691
667
|
routerContext: TRouterContext
|
|
692
668
|
loaderData: TLoaderData
|
|
693
669
|
loaderDeps: TLoaderDeps
|
|
694
670
|
}
|
|
695
671
|
|
|
696
|
-
init = (opts: { originalIndex: number }) => {
|
|
672
|
+
init = (opts: { originalIndex: number }): void => {
|
|
697
673
|
this.originalIndex = opts.originalIndex
|
|
698
674
|
|
|
699
675
|
const options = this.options as
|
|
@@ -768,7 +744,7 @@ export class Route<
|
|
|
768
744
|
this.to = fullPath as TrimPathRight<TFullPath>
|
|
769
745
|
}
|
|
770
746
|
|
|
771
|
-
addChildren = <TNewChildren extends
|
|
747
|
+
addChildren = <const TNewChildren extends ReadonlyArray<AnyRoute>>(
|
|
772
748
|
children: TNewChildren,
|
|
773
749
|
): Route<
|
|
774
750
|
TParentRoute,
|
|
@@ -790,8 +766,7 @@ export class Route<
|
|
|
790
766
|
TLoaderDeps,
|
|
791
767
|
TLoaderDataReturn,
|
|
792
768
|
TLoaderData,
|
|
793
|
-
TNewChildren
|
|
794
|
-
TRouteTree
|
|
769
|
+
TNewChildren
|
|
795
770
|
> => {
|
|
796
771
|
this.children = children as any
|
|
797
772
|
return this as any
|
|
@@ -826,25 +801,23 @@ export class Route<
|
|
|
826
801
|
TRouterContext,
|
|
827
802
|
TLoaderDeps,
|
|
828
803
|
TNewLoaderData,
|
|
829
|
-
TChildren
|
|
830
|
-
TRouteTree
|
|
804
|
+
TChildren
|
|
831
805
|
>
|
|
832
806
|
}
|
|
833
807
|
|
|
834
808
|
update = (
|
|
835
809
|
options: UpdatableRouteOptions<TAllParams, TFullSearchSchema, TLoaderData>,
|
|
836
|
-
) => {
|
|
810
|
+
): this => {
|
|
837
811
|
Object.assign(this.options, options)
|
|
838
812
|
return this
|
|
839
813
|
}
|
|
840
814
|
|
|
841
|
-
lazy = (lazyFn: () => Promise<LazyRoute<any>>) => {
|
|
815
|
+
lazy = (lazyFn: () => Promise<LazyRoute<any>>): this => {
|
|
842
816
|
this.lazyFn = lazyFn
|
|
843
817
|
return this
|
|
844
818
|
}
|
|
845
819
|
|
|
846
820
|
useMatch = <
|
|
847
|
-
// eslint-disable-next-line no-shadow
|
|
848
821
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
849
822
|
TRouteMatchState = RouteMatch<TRouteTree, TId>,
|
|
850
823
|
TSelected = TRouteMatchState,
|
|
@@ -854,8 +827,8 @@ export class Route<
|
|
|
854
827
|
return useMatch({ ...opts, from: this.id })
|
|
855
828
|
}
|
|
856
829
|
|
|
857
|
-
useRouteContext = <TSelected = TAllContext
|
|
858
|
-
select?: (search: TAllContext) => TSelected
|
|
830
|
+
useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {
|
|
831
|
+
select?: (search: Expand<TAllContext>) => TSelected
|
|
859
832
|
}): TSelected => {
|
|
860
833
|
return useMatch({
|
|
861
834
|
...opts,
|
|
@@ -864,14 +837,14 @@ export class Route<
|
|
|
864
837
|
})
|
|
865
838
|
}
|
|
866
839
|
|
|
867
|
-
useSearch = <TSelected = TFullSearchSchema
|
|
868
|
-
select?: (search: TFullSearchSchema) => TSelected
|
|
840
|
+
useSearch = <TSelected = Expand<TFullSearchSchema>>(opts?: {
|
|
841
|
+
select?: (search: Expand<TFullSearchSchema>) => TSelected
|
|
869
842
|
}): TSelected => {
|
|
870
843
|
return useSearch({ ...opts, from: this.id })
|
|
871
844
|
}
|
|
872
845
|
|
|
873
|
-
useParams = <TSelected = TAllParams
|
|
874
|
-
select?: (search: TAllParams) => TSelected
|
|
846
|
+
useParams = <TSelected = Expand<TAllParams>>(opts?: {
|
|
847
|
+
select?: (search: Expand<TAllParams>) => TSelected
|
|
875
848
|
}): TSelected => {
|
|
876
849
|
return useParams({ ...opts, from: this.id })
|
|
877
850
|
}
|
|
@@ -888,7 +861,7 @@ export class Route<
|
|
|
888
861
|
return useLoaderData({ ...opts, from: this.id } as any)
|
|
889
862
|
}
|
|
890
863
|
|
|
891
|
-
useNavigate = () => {
|
|
864
|
+
useNavigate = (): UseNavigateResult<string> => {
|
|
892
865
|
return useNavigate({ from: this.id })
|
|
893
866
|
}
|
|
894
867
|
}
|
|
@@ -908,32 +881,23 @@ export function createRoute<
|
|
|
908
881
|
>,
|
|
909
882
|
TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
|
|
910
883
|
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
911
|
-
TSearchSchemaUsed extends
|
|
912
|
-
string,
|
|
913
|
-
any
|
|
914
|
-
> = TSearchSchemaInput extends SearchSchemaInput
|
|
884
|
+
TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
|
|
915
885
|
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
|
|
916
886
|
: TSearchSchema,
|
|
917
|
-
TFullSearchSchemaInput
|
|
918
|
-
string,
|
|
919
|
-
any
|
|
920
|
-
> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
|
|
921
|
-
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
922
|
-
TParams extends RouteConstraints['TParams'] = Expand<
|
|
923
|
-
Record<ParsePathParams<TPath>, string>
|
|
924
|
-
>,
|
|
925
|
-
TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<
|
|
887
|
+
TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
926
888
|
TParentRoute,
|
|
927
|
-
|
|
889
|
+
TSearchSchemaUsed
|
|
928
890
|
>,
|
|
891
|
+
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
892
|
+
TParams = Record<ParsePathParams<TPath>, string>,
|
|
893
|
+
TAllParams = ResolveAllParams<TParentRoute, TParams>,
|
|
929
894
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
930
|
-
TRouteContext
|
|
931
|
-
TRouteContextReturn,
|
|
932
|
-
] extends [never]
|
|
895
|
+
TRouteContext = [TRouteContextReturn] extends [never]
|
|
933
896
|
? RouteContext
|
|
934
897
|
: TRouteContextReturn,
|
|
935
|
-
TAllContext =
|
|
936
|
-
|
|
898
|
+
TAllContext = Assign<
|
|
899
|
+
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
900
|
+
TRouteContext
|
|
937
901
|
>,
|
|
938
902
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
939
903
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -942,7 +906,6 @@ export function createRoute<
|
|
|
942
906
|
? undefined
|
|
943
907
|
: TLoaderDataReturn,
|
|
944
908
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
945
|
-
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
946
909
|
>(
|
|
947
910
|
options: RouteOptions<
|
|
948
911
|
TParentRoute,
|
|
@@ -984,8 +947,7 @@ export function createRoute<
|
|
|
984
947
|
TLoaderDeps,
|
|
985
948
|
TLoaderDataReturn,
|
|
986
949
|
TLoaderData,
|
|
987
|
-
TChildren
|
|
988
|
-
TRouteTree
|
|
950
|
+
TChildren
|
|
989
951
|
>(options)
|
|
990
952
|
}
|
|
991
953
|
|
|
@@ -1008,7 +970,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
1008
970
|
>(
|
|
1009
971
|
options?: Omit<
|
|
1010
972
|
RouteOptions<
|
|
1011
|
-
|
|
973
|
+
any, // TParentRoute
|
|
1012
974
|
RootRouteId, // TCustomId
|
|
1013
975
|
'', // TPath
|
|
1014
976
|
TSearchSchemaInput, // TSearchSchemaInput
|
|
@@ -1021,7 +983,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
1021
983
|
TRouteContextReturn, // TRouteContextReturn
|
|
1022
984
|
TRouteContext, // TRouteContext
|
|
1023
985
|
TRouterContext,
|
|
1024
|
-
|
|
986
|
+
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
1025
987
|
TLoaderDeps,
|
|
1026
988
|
TLoaderDataReturn, // TLoaderDataReturn,
|
|
1027
989
|
TLoaderData // TLoaderData,
|
|
@@ -1057,17 +1019,19 @@ export type RootSearchSchema = {
|
|
|
1057
1019
|
}
|
|
1058
1020
|
|
|
1059
1021
|
export class RootRoute<
|
|
1060
|
-
TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
|
|
1061
|
-
TSearchSchema extends Record<string, any> = RootSearchSchema,
|
|
1062
|
-
TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
|
|
1022
|
+
in out TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
|
|
1023
|
+
in out TSearchSchema extends Record<string, any> = RootSearchSchema,
|
|
1024
|
+
in out TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
|
|
1063
1025
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
1064
|
-
TRouteContext extends RouteContext = [TRouteContextReturn] extends [
|
|
1026
|
+
in out TRouteContext extends RouteContext = [TRouteContextReturn] extends [
|
|
1027
|
+
never,
|
|
1028
|
+
]
|
|
1065
1029
|
? RouteContext
|
|
1066
1030
|
: TRouteContextReturn,
|
|
1067
|
-
TRouterContext extends {} = {},
|
|
1031
|
+
in out TRouterContext extends {} = {},
|
|
1068
1032
|
TLoaderDeps extends Record<string, any> = {},
|
|
1069
1033
|
TLoaderDataReturn = unknown,
|
|
1070
|
-
TLoaderData = [TLoaderDataReturn] extends [never]
|
|
1034
|
+
in out TLoaderData = [TLoaderDataReturn] extends [never]
|
|
1071
1035
|
? undefined
|
|
1072
1036
|
: TLoaderDataReturn,
|
|
1073
1037
|
> extends Route<
|
|
@@ -1090,8 +1054,7 @@ export class RootRoute<
|
|
|
1090
1054
|
TLoaderDeps,
|
|
1091
1055
|
TLoaderDataReturn,
|
|
1092
1056
|
TLoaderData,
|
|
1093
|
-
any
|
|
1094
|
-
any // TRouteTree
|
|
1057
|
+
any // TChildren
|
|
1095
1058
|
> {
|
|
1096
1059
|
/**
|
|
1097
1060
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
@@ -1099,7 +1062,7 @@ export class RootRoute<
|
|
|
1099
1062
|
constructor(
|
|
1100
1063
|
options?: Omit<
|
|
1101
1064
|
RouteOptions<
|
|
1102
|
-
|
|
1065
|
+
any, // TParentRoute
|
|
1103
1066
|
RootRouteId, // TCustomId
|
|
1104
1067
|
'', // TPath
|
|
1105
1068
|
TSearchSchemaInput, // TSearchSchemaInput
|
|
@@ -1146,7 +1109,7 @@ export function createRootRoute<
|
|
|
1146
1109
|
>(
|
|
1147
1110
|
options?: Omit<
|
|
1148
1111
|
RouteOptions<
|
|
1149
|
-
|
|
1112
|
+
any, // TParentRoute
|
|
1150
1113
|
RootRouteId, // TCustomId
|
|
1151
1114
|
'', // TPath
|
|
1152
1115
|
TSearchSchemaInput, // TSearchSchemaInput
|
|
@@ -1295,8 +1258,9 @@ export class NotFoundRoute<
|
|
|
1295
1258
|
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
1296
1259
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext,
|
|
1297
1260
|
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
1298
|
-
TAllContext =
|
|
1299
|
-
|
|
1261
|
+
TAllContext = Assign<
|
|
1262
|
+
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
1263
|
+
TRouteContext
|
|
1300
1264
|
>,
|
|
1301
1265
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
1302
1266
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -1305,7 +1269,6 @@ export class NotFoundRoute<
|
|
|
1305
1269
|
? undefined
|
|
1306
1270
|
: TLoaderDataReturn,
|
|
1307
1271
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
1308
|
-
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
1309
1272
|
> extends Route<
|
|
1310
1273
|
TParentRoute,
|
|
1311
1274
|
'/404',
|
|
@@ -1326,8 +1289,7 @@ export class NotFoundRoute<
|
|
|
1326
1289
|
TLoaderDeps,
|
|
1327
1290
|
TLoaderDataReturn,
|
|
1328
1291
|
TLoaderData,
|
|
1329
|
-
TChildren
|
|
1330
|
-
TRouteTree
|
|
1292
|
+
TChildren
|
|
1331
1293
|
> {
|
|
1332
1294
|
constructor(
|
|
1333
1295
|
options: Omit<
|