@tanstack/react-router 1.27.0 → 1.28.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.
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +9 -10
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +32 -24
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +42 -45
- package/dist/cjs/routeInfo.d.cts +5 -7
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -1
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +5 -3
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +9 -10
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/link.d.ts +32 -24
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +42 -45
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +5 -7
- package/dist/esm/router.d.ts +1 -1
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/utils.d.ts +5 -3
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +2 -2
- package/src/fileRoute.ts +17 -36
- package/src/index.tsx +0 -1
- package/src/link.tsx +187 -82
- package/src/route.ts +153 -186
- package/src/routeInfo.ts +5 -7
- package/src/router.ts +5 -5
- package/src/useParams.tsx +2 -2
- package/src/utils.ts +10 -6
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,48 @@ 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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
+
}) =>
|
|
258
|
+
| Array<JSX.IntrinsicElements['meta']>
|
|
259
|
+
| Promise<Array<JSX.IntrinsicElements['meta']>>
|
|
260
|
+
links?: () => Array<JSX.IntrinsicElements['link']>
|
|
261
|
+
scripts?: () => Array<JSX.IntrinsicElements['script']>
|
|
262
|
+
headers?: (ctx: {
|
|
263
|
+
loaderData: TLoaderData
|
|
264
|
+
}) => Promise<Record<string, string>> | Record<string, string>
|
|
265
|
+
} & UpdatableStaticRouteOption
|
|
268
266
|
|
|
269
267
|
export type UpdatableStaticRouteOption =
|
|
270
268
|
{} extends PickRequired<StaticDataRouteOption>
|
|
@@ -323,26 +321,26 @@ export type SearchSchemaValidatorFn<TInput, TReturn> = (
|
|
|
323
321
|
) => TReturn
|
|
324
322
|
|
|
325
323
|
export type RouteLoaderFn<
|
|
326
|
-
TAllParams = {},
|
|
327
|
-
TLoaderDeps extends Record<string, any> = {},
|
|
328
|
-
TAllContext = AnyContext,
|
|
329
|
-
|
|
324
|
+
in out TAllParams = {},
|
|
325
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
326
|
+
in out TAllContext = AnyContext,
|
|
327
|
+
in out TRouteContext = AnyContext,
|
|
330
328
|
TLoaderData = unknown,
|
|
331
329
|
> = (
|
|
332
330
|
match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,
|
|
333
331
|
) => Promise<TLoaderData> | TLoaderData
|
|
334
332
|
|
|
335
333
|
export interface LoaderFnContext<
|
|
336
|
-
TAllParams = {},
|
|
337
|
-
TLoaderDeps = {},
|
|
338
|
-
TAllContext = AnyContext,
|
|
339
|
-
|
|
334
|
+
in out TAllParams = {},
|
|
335
|
+
in out TLoaderDeps = {},
|
|
336
|
+
in out TAllContext = AnyContext,
|
|
337
|
+
in out TRouteContext = AnyContext,
|
|
340
338
|
> {
|
|
341
339
|
abortController: AbortController
|
|
342
340
|
preload: boolean
|
|
343
341
|
params: TAllParams
|
|
344
342
|
deps: TLoaderDeps
|
|
345
|
-
context:
|
|
343
|
+
context: Assign<TAllContext, TRouteContext>
|
|
346
344
|
location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps
|
|
347
345
|
/**
|
|
348
346
|
* @deprecated Use `throw redirect({ to: '/somewhere' })` instead
|
|
@@ -382,25 +380,21 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
|
|
|
382
380
|
export type ResolveFullSearchSchema<
|
|
383
381
|
TParentRoute extends AnyRoute,
|
|
384
382
|
TSearchSchema,
|
|
385
|
-
> =
|
|
386
|
-
|
|
387
|
-
TParentRoute['
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
TSearchSchema
|
|
391
|
-
>
|
|
383
|
+
> = Assign<
|
|
384
|
+
TParentRoute['id'] extends RootRouteId
|
|
385
|
+
? Omit<TParentRoute['types']['searchSchema'], keyof RootSearchSchema>
|
|
386
|
+
: TParentRoute['types']['fullSearchSchema'],
|
|
387
|
+
TSearchSchema
|
|
392
388
|
>
|
|
393
389
|
|
|
394
390
|
export type ResolveFullSearchSchemaInput<
|
|
395
391
|
TParentRoute extends AnyRoute,
|
|
396
392
|
TSearchSchemaUsed,
|
|
397
|
-
> =
|
|
398
|
-
|
|
399
|
-
TParentRoute['
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
TSearchSchemaUsed
|
|
403
|
-
>
|
|
393
|
+
> = Assign<
|
|
394
|
+
TParentRoute['id'] extends RootRouteId
|
|
395
|
+
? Omit<TParentRoute['types']['searchSchemaInput'], keyof RootSearchSchema>
|
|
396
|
+
: TParentRoute['types']['fullSearchSchemaInput'],
|
|
397
|
+
TSearchSchemaUsed
|
|
404
398
|
>
|
|
405
399
|
|
|
406
400
|
export interface AnyRoute
|
|
@@ -424,22 +418,16 @@ export interface AnyRoute
|
|
|
424
418
|
any,
|
|
425
419
|
any,
|
|
426
420
|
any,
|
|
427
|
-
any,
|
|
428
421
|
any
|
|
429
422
|
> {}
|
|
430
423
|
|
|
431
424
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
432
425
|
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>
|
|
433
426
|
|
|
434
|
-
export type ResolveAllParams<
|
|
435
|
-
TParentRoute extends AnyRoute,
|
|
436
|
-
TParams extends AnyPathParams,
|
|
437
|
-
> =
|
|
427
|
+
export type ResolveAllParams<TParentRoute extends AnyRoute, TParams> =
|
|
438
428
|
Record<never, string> extends TParentRoute['types']['allParams']
|
|
439
429
|
? TParams
|
|
440
|
-
:
|
|
441
|
-
UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}
|
|
442
|
-
>
|
|
430
|
+
: UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}
|
|
443
431
|
|
|
444
432
|
export type RouteConstraints = {
|
|
445
433
|
TParentRoute: AnyRoute
|
|
@@ -463,9 +451,9 @@ export function getRouteApi<
|
|
|
463
451
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
464
452
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
465
453
|
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
|
|
466
|
-
TAllParams
|
|
454
|
+
TAllParams = TRoute['types']['allParams'],
|
|
467
455
|
TAllContext = TRoute['types']['allContext'],
|
|
468
|
-
TLoaderDeps
|
|
456
|
+
TLoaderDeps = TRoute['types']['loaderDeps'],
|
|
469
457
|
TLoaderData = TRoute['types']['loaderData'],
|
|
470
458
|
>(id: TId) {
|
|
471
459
|
return new RouteApi<
|
|
@@ -483,9 +471,9 @@ export class RouteApi<
|
|
|
483
471
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
484
472
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
485
473
|
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
|
|
486
|
-
TAllParams
|
|
474
|
+
TAllParams = TRoute['types']['allParams'],
|
|
487
475
|
TAllContext = TRoute['types']['allContext'],
|
|
488
|
-
TLoaderDeps
|
|
476
|
+
TLoaderDeps = TRoute['types']['loaderDeps'],
|
|
489
477
|
TLoaderData = TRoute['types']['loaderData'],
|
|
490
478
|
> {
|
|
491
479
|
id: TId
|
|
@@ -507,8 +495,8 @@ export class RouteApi<
|
|
|
507
495
|
return useMatch({ select: opts?.select, from: this.id })
|
|
508
496
|
}
|
|
509
497
|
|
|
510
|
-
useRouteContext = <TSelected = TAllContext
|
|
511
|
-
select?: (s: TAllContext) => TSelected
|
|
498
|
+
useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {
|
|
499
|
+
select?: (s: Expand<TAllContext>) => TSelected
|
|
512
500
|
}): TSelected => {
|
|
513
501
|
return useMatch({
|
|
514
502
|
from: this.id,
|
|
@@ -516,14 +504,14 @@ export class RouteApi<
|
|
|
516
504
|
})
|
|
517
505
|
}
|
|
518
506
|
|
|
519
|
-
useSearch = <TSelected = TFullSearchSchema
|
|
520
|
-
select?: (s: TFullSearchSchema) => TSelected
|
|
507
|
+
useSearch = <TSelected = Expand<TFullSearchSchema>>(opts?: {
|
|
508
|
+
select?: (s: Expand<TFullSearchSchema>) => TSelected
|
|
521
509
|
}): TSelected => {
|
|
522
510
|
return useSearch({ ...opts, from: this.id })
|
|
523
511
|
}
|
|
524
512
|
|
|
525
|
-
useParams = <TSelected = TAllParams
|
|
526
|
-
select?: (s: TAllParams) => TSelected
|
|
513
|
+
useParams = <TSelected = Expand<TAllParams>>(opts?: {
|
|
514
|
+
select?: (s: Expand<TAllParams>) => TSelected
|
|
527
515
|
}): TSelected => {
|
|
528
516
|
return useParams({ ...opts, from: this.id })
|
|
529
517
|
}
|
|
@@ -550,55 +538,48 @@ export class RouteApi<
|
|
|
550
538
|
}
|
|
551
539
|
|
|
552
540
|
export class Route<
|
|
553
|
-
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
541
|
+
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
554
542
|
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
555
|
-
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
543
|
+
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
556
544
|
TParentRoute,
|
|
557
545
|
TPath
|
|
558
546
|
>,
|
|
559
|
-
TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
560
|
-
TId extends RouteConstraints['TId'] = ResolveId<
|
|
547
|
+
in out TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
548
|
+
in out TId extends RouteConstraints['TId'] = ResolveId<
|
|
561
549
|
TParentRoute,
|
|
562
550
|
TCustomId,
|
|
563
551
|
TPath
|
|
564
552
|
>,
|
|
565
|
-
TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
|
|
566
|
-
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
567
|
-
TSearchSchemaUsed extends
|
|
568
|
-
string,
|
|
569
|
-
any
|
|
570
|
-
> = TSearchSchemaInput extends SearchSchemaInput
|
|
553
|
+
in out TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
|
|
554
|
+
in out TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
555
|
+
in out TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
|
|
571
556
|
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
|
|
572
557
|
: 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>
|
|
558
|
+
in out TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
559
|
+
TParentRoute,
|
|
560
|
+
TSearchSchemaUsed
|
|
580
561
|
>,
|
|
581
|
-
|
|
562
|
+
in out TFullSearchSchema = ResolveFullSearchSchema<
|
|
582
563
|
TParentRoute,
|
|
583
|
-
|
|
564
|
+
TSearchSchema
|
|
584
565
|
>,
|
|
566
|
+
in out TParams = Record<ParsePathParams<TPath>, string>,
|
|
567
|
+
in out TAllParams = ResolveAllParams<TParentRoute, TParams>,
|
|
585
568
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
586
|
-
in out TRouteContext
|
|
587
|
-
TRouteContextReturn,
|
|
588
|
-
] extends [never]
|
|
569
|
+
in out TRouteContext = [TRouteContextReturn] extends [never]
|
|
589
570
|
? RouteContext
|
|
590
571
|
: TRouteContextReturn,
|
|
591
|
-
in out TAllContext =
|
|
592
|
-
|
|
572
|
+
in out TAllContext = Assign<
|
|
573
|
+
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
574
|
+
TRouteContext
|
|
593
575
|
>,
|
|
594
|
-
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
595
|
-
TLoaderDeps extends Record<string, any> = {},
|
|
576
|
+
in out TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
577
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
596
578
|
TLoaderDataReturn = unknown,
|
|
597
|
-
TLoaderData = [TLoaderDataReturn] extends [never]
|
|
579
|
+
in out TLoaderData = [TLoaderDataReturn] extends [never]
|
|
598
580
|
? undefined
|
|
599
581
|
: TLoaderDataReturn,
|
|
600
|
-
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
601
|
-
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
582
|
+
in out TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
602
583
|
> {
|
|
603
584
|
isRoot: TParentRoute extends Route<any> ? true : false
|
|
604
585
|
options: RouteOptions<
|
|
@@ -687,13 +668,12 @@ export class Route<
|
|
|
687
668
|
routeContext: TRouteContext
|
|
688
669
|
allContext: TAllContext
|
|
689
670
|
children: TChildren
|
|
690
|
-
routeTree: TRouteTree
|
|
691
671
|
routerContext: TRouterContext
|
|
692
672
|
loaderData: TLoaderData
|
|
693
673
|
loaderDeps: TLoaderDeps
|
|
694
674
|
}
|
|
695
675
|
|
|
696
|
-
init = (opts: { originalIndex: number }) => {
|
|
676
|
+
init = (opts: { originalIndex: number }): void => {
|
|
697
677
|
this.originalIndex = opts.originalIndex
|
|
698
678
|
|
|
699
679
|
const options = this.options as
|
|
@@ -768,7 +748,7 @@ export class Route<
|
|
|
768
748
|
this.to = fullPath as TrimPathRight<TFullPath>
|
|
769
749
|
}
|
|
770
750
|
|
|
771
|
-
addChildren = <TNewChildren extends
|
|
751
|
+
addChildren = <const TNewChildren extends ReadonlyArray<AnyRoute>>(
|
|
772
752
|
children: TNewChildren,
|
|
773
753
|
): Route<
|
|
774
754
|
TParentRoute,
|
|
@@ -790,8 +770,7 @@ export class Route<
|
|
|
790
770
|
TLoaderDeps,
|
|
791
771
|
TLoaderDataReturn,
|
|
792
772
|
TLoaderData,
|
|
793
|
-
TNewChildren
|
|
794
|
-
TRouteTree
|
|
773
|
+
TNewChildren
|
|
795
774
|
> => {
|
|
796
775
|
this.children = children as any
|
|
797
776
|
return this as any
|
|
@@ -826,19 +805,18 @@ export class Route<
|
|
|
826
805
|
TRouterContext,
|
|
827
806
|
TLoaderDeps,
|
|
828
807
|
TNewLoaderData,
|
|
829
|
-
TChildren
|
|
830
|
-
TRouteTree
|
|
808
|
+
TChildren
|
|
831
809
|
>
|
|
832
810
|
}
|
|
833
811
|
|
|
834
812
|
update = (
|
|
835
813
|
options: UpdatableRouteOptions<TAllParams, TFullSearchSchema, TLoaderData>,
|
|
836
|
-
) => {
|
|
814
|
+
): this => {
|
|
837
815
|
Object.assign(this.options, options)
|
|
838
816
|
return this
|
|
839
817
|
}
|
|
840
818
|
|
|
841
|
-
lazy = (lazyFn: () => Promise<LazyRoute<any>>) => {
|
|
819
|
+
lazy = (lazyFn: () => Promise<LazyRoute<any>>): this => {
|
|
842
820
|
this.lazyFn = lazyFn
|
|
843
821
|
return this
|
|
844
822
|
}
|
|
@@ -854,8 +832,8 @@ export class Route<
|
|
|
854
832
|
return useMatch({ ...opts, from: this.id })
|
|
855
833
|
}
|
|
856
834
|
|
|
857
|
-
useRouteContext = <TSelected = TAllContext
|
|
858
|
-
select?: (search: TAllContext) => TSelected
|
|
835
|
+
useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {
|
|
836
|
+
select?: (search: Expand<TAllContext>) => TSelected
|
|
859
837
|
}): TSelected => {
|
|
860
838
|
return useMatch({
|
|
861
839
|
...opts,
|
|
@@ -864,14 +842,14 @@ export class Route<
|
|
|
864
842
|
})
|
|
865
843
|
}
|
|
866
844
|
|
|
867
|
-
useSearch = <TSelected = TFullSearchSchema
|
|
868
|
-
select?: (search: TFullSearchSchema) => TSelected
|
|
845
|
+
useSearch = <TSelected = Expand<TFullSearchSchema>>(opts?: {
|
|
846
|
+
select?: (search: Expand<TFullSearchSchema>) => TSelected
|
|
869
847
|
}): TSelected => {
|
|
870
848
|
return useSearch({ ...opts, from: this.id })
|
|
871
849
|
}
|
|
872
850
|
|
|
873
|
-
useParams = <TSelected = TAllParams
|
|
874
|
-
select?: (search: TAllParams) => TSelected
|
|
851
|
+
useParams = <TSelected = Expand<TAllParams>>(opts?: {
|
|
852
|
+
select?: (search: Expand<TAllParams>) => TSelected
|
|
875
853
|
}): TSelected => {
|
|
876
854
|
return useParams({ ...opts, from: this.id })
|
|
877
855
|
}
|
|
@@ -888,7 +866,7 @@ export class Route<
|
|
|
888
866
|
return useLoaderData({ ...opts, from: this.id } as any)
|
|
889
867
|
}
|
|
890
868
|
|
|
891
|
-
useNavigate = () => {
|
|
869
|
+
useNavigate = (): UseNavigateResult<string> => {
|
|
892
870
|
return useNavigate({ from: this.id })
|
|
893
871
|
}
|
|
894
872
|
}
|
|
@@ -908,32 +886,23 @@ export function createRoute<
|
|
|
908
886
|
>,
|
|
909
887
|
TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
|
|
910
888
|
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
911
|
-
TSearchSchemaUsed extends
|
|
912
|
-
string,
|
|
913
|
-
any
|
|
914
|
-
> = TSearchSchemaInput extends SearchSchemaInput
|
|
889
|
+
TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
|
|
915
890
|
? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
|
|
916
891
|
: 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<
|
|
892
|
+
TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
|
926
893
|
TParentRoute,
|
|
927
|
-
|
|
894
|
+
TSearchSchemaUsed
|
|
928
895
|
>,
|
|
896
|
+
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
897
|
+
TParams = Record<ParsePathParams<TPath>, string>,
|
|
898
|
+
TAllParams = ResolveAllParams<TParentRoute, TParams>,
|
|
929
899
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
930
|
-
TRouteContext
|
|
931
|
-
TRouteContextReturn,
|
|
932
|
-
] extends [never]
|
|
900
|
+
TRouteContext = [TRouteContextReturn] extends [never]
|
|
933
901
|
? RouteContext
|
|
934
902
|
: TRouteContextReturn,
|
|
935
|
-
TAllContext =
|
|
936
|
-
|
|
903
|
+
TAllContext = Assign<
|
|
904
|
+
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
905
|
+
TRouteContext
|
|
937
906
|
>,
|
|
938
907
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
939
908
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -942,7 +911,6 @@ export function createRoute<
|
|
|
942
911
|
? undefined
|
|
943
912
|
: TLoaderDataReturn,
|
|
944
913
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
945
|
-
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
946
914
|
>(
|
|
947
915
|
options: RouteOptions<
|
|
948
916
|
TParentRoute,
|
|
@@ -984,8 +952,7 @@ export function createRoute<
|
|
|
984
952
|
TLoaderDeps,
|
|
985
953
|
TLoaderDataReturn,
|
|
986
954
|
TLoaderData,
|
|
987
|
-
TChildren
|
|
988
|
-
TRouteTree
|
|
955
|
+
TChildren
|
|
989
956
|
>(options)
|
|
990
957
|
}
|
|
991
958
|
|
|
@@ -1008,7 +975,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
1008
975
|
>(
|
|
1009
976
|
options?: Omit<
|
|
1010
977
|
RouteOptions<
|
|
1011
|
-
|
|
978
|
+
any, // TParentRoute
|
|
1012
979
|
RootRouteId, // TCustomId
|
|
1013
980
|
'', // TPath
|
|
1014
981
|
TSearchSchemaInput, // TSearchSchemaInput
|
|
@@ -1021,7 +988,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
1021
988
|
TRouteContextReturn, // TRouteContextReturn
|
|
1022
989
|
TRouteContext, // TRouteContext
|
|
1023
990
|
TRouterContext,
|
|
1024
|
-
|
|
991
|
+
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
1025
992
|
TLoaderDeps,
|
|
1026
993
|
TLoaderDataReturn, // TLoaderDataReturn,
|
|
1027
994
|
TLoaderData // TLoaderData,
|
|
@@ -1057,17 +1024,19 @@ export type RootSearchSchema = {
|
|
|
1057
1024
|
}
|
|
1058
1025
|
|
|
1059
1026
|
export class RootRoute<
|
|
1060
|
-
TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
|
|
1061
|
-
TSearchSchema extends Record<string, any> = RootSearchSchema,
|
|
1062
|
-
TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
|
|
1027
|
+
in out TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
|
|
1028
|
+
in out TSearchSchema extends Record<string, any> = RootSearchSchema,
|
|
1029
|
+
in out TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
|
|
1063
1030
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
1064
|
-
TRouteContext extends RouteContext = [TRouteContextReturn] extends [
|
|
1031
|
+
in out TRouteContext extends RouteContext = [TRouteContextReturn] extends [
|
|
1032
|
+
never,
|
|
1033
|
+
]
|
|
1065
1034
|
? RouteContext
|
|
1066
1035
|
: TRouteContextReturn,
|
|
1067
|
-
TRouterContext extends {} = {},
|
|
1036
|
+
in out TRouterContext extends {} = {},
|
|
1068
1037
|
TLoaderDeps extends Record<string, any> = {},
|
|
1069
1038
|
TLoaderDataReturn = unknown,
|
|
1070
|
-
TLoaderData = [TLoaderDataReturn] extends [never]
|
|
1039
|
+
in out TLoaderData = [TLoaderDataReturn] extends [never]
|
|
1071
1040
|
? undefined
|
|
1072
1041
|
: TLoaderDataReturn,
|
|
1073
1042
|
> extends Route<
|
|
@@ -1090,8 +1059,7 @@ export class RootRoute<
|
|
|
1090
1059
|
TLoaderDeps,
|
|
1091
1060
|
TLoaderDataReturn,
|
|
1092
1061
|
TLoaderData,
|
|
1093
|
-
any
|
|
1094
|
-
any // TRouteTree
|
|
1062
|
+
any // TChildren
|
|
1095
1063
|
> {
|
|
1096
1064
|
/**
|
|
1097
1065
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
@@ -1099,7 +1067,7 @@ export class RootRoute<
|
|
|
1099
1067
|
constructor(
|
|
1100
1068
|
options?: Omit<
|
|
1101
1069
|
RouteOptions<
|
|
1102
|
-
|
|
1070
|
+
any, // TParentRoute
|
|
1103
1071
|
RootRouteId, // TCustomId
|
|
1104
1072
|
'', // TPath
|
|
1105
1073
|
TSearchSchemaInput, // TSearchSchemaInput
|
|
@@ -1146,7 +1114,7 @@ export function createRootRoute<
|
|
|
1146
1114
|
>(
|
|
1147
1115
|
options?: Omit<
|
|
1148
1116
|
RouteOptions<
|
|
1149
|
-
|
|
1117
|
+
any, // TParentRoute
|
|
1150
1118
|
RootRouteId, // TCustomId
|
|
1151
1119
|
'', // TPath
|
|
1152
1120
|
TSearchSchemaInput, // TSearchSchemaInput
|
|
@@ -1295,8 +1263,9 @@ export class NotFoundRoute<
|
|
|
1295
1263
|
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
1296
1264
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext,
|
|
1297
1265
|
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
1298
|
-
TAllContext =
|
|
1299
|
-
|
|
1266
|
+
TAllContext = Assign<
|
|
1267
|
+
IsAny<TParentRoute['types']['allContext'], {}>,
|
|
1268
|
+
TRouteContext
|
|
1300
1269
|
>,
|
|
1301
1270
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
1302
1271
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -1305,7 +1274,6 @@ export class NotFoundRoute<
|
|
|
1305
1274
|
? undefined
|
|
1306
1275
|
: TLoaderDataReturn,
|
|
1307
1276
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
1308
|
-
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
1309
1277
|
> extends Route<
|
|
1310
1278
|
TParentRoute,
|
|
1311
1279
|
'/404',
|
|
@@ -1326,8 +1294,7 @@ export class NotFoundRoute<
|
|
|
1326
1294
|
TLoaderDeps,
|
|
1327
1295
|
TLoaderDataReturn,
|
|
1328
1296
|
TLoaderData,
|
|
1329
|
-
TChildren
|
|
1330
|
-
TRouteTree
|
|
1297
|
+
TChildren
|
|
1331
1298
|
> {
|
|
1332
1299
|
constructor(
|
|
1333
1300
|
options: Omit<
|