@tanstack/react-router 1.89.2 → 1.91.0
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/index.d.cts +3 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +19 -23
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +3 -3
- package/dist/cjs/routeInfo.d.cts +3 -3
- package/dist/cjs/router.cjs +28 -24
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -2
- package/dist/cjs/typePrimitives.d.cts +62 -0
- package/dist/cjs/useBlocker.cjs +111 -23
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +58 -13
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +3 -2
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/link.d.ts +19 -23
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +3 -3
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +3 -3
- package/dist/esm/router.d.ts +3 -2
- package/dist/esm/router.js +28 -24
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +62 -0
- package/dist/esm/useBlocker.d.ts +58 -13
- package/dist/esm/useBlocker.js +111 -23
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/utils.d.ts +3 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +3 -6
- package/src/link.tsx +107 -144
- package/src/route.ts +14 -7
- package/src/routeInfo.ts +6 -13
- package/src/router.ts +34 -32
- package/src/typePrimitives.ts +168 -0
- package/src/useBlocker.tsx +245 -41
- package/src/utils.ts +9 -5
package/src/link.tsx
CHANGED
|
@@ -35,6 +35,7 @@ import type {
|
|
|
35
35
|
} from './router'
|
|
36
36
|
import type {
|
|
37
37
|
Constrain,
|
|
38
|
+
ConstrainLiteral,
|
|
38
39
|
Expand,
|
|
39
40
|
MakeDifferenceOptional,
|
|
40
41
|
NoInfer,
|
|
@@ -45,96 +46,55 @@ import type {
|
|
|
45
46
|
} from './utils'
|
|
46
47
|
import type { ReactNode } from 'react'
|
|
47
48
|
|
|
48
|
-
export type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
?
|
|
54
|
-
:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: TValue extends string
|
|
60
|
-
? CleanPath<TValue> extends ''
|
|
61
|
-
? []
|
|
62
|
-
: TIncludeTrailingSlash extends true
|
|
63
|
-
? CleanPath<TValue> extends `${infer T}/`
|
|
64
|
-
? [...Split<T>, '/']
|
|
65
|
-
: CleanPath<TValue> extends `/${infer U}`
|
|
66
|
-
? Split<U>
|
|
67
|
-
: CleanPath<TValue> extends `${infer T}/${infer U}`
|
|
68
|
-
? [...Split<T>, ...Split<U>]
|
|
69
|
-
: [TValue]
|
|
70
|
-
: CleanPath<TValue> extends `${infer T}/${infer U}`
|
|
71
|
-
? [...Split<T>, ...Split<U>]
|
|
72
|
-
: TValue extends string
|
|
73
|
-
? [TValue]
|
|
74
|
-
: never
|
|
75
|
-
: never
|
|
76
|
-
: never
|
|
77
|
-
|
|
78
|
-
export type ParsePathParams<
|
|
79
|
-
T extends string,
|
|
80
|
-
TAcc = never,
|
|
81
|
-
> = T extends `${string}$${string}`
|
|
82
|
-
? T extends `${string}$${infer TPossiblyParam}`
|
|
83
|
-
? TPossiblyParam extends `${string}/${string}`
|
|
84
|
-
? TPossiblyParam extends `${infer TParam}/${infer TRest}`
|
|
85
|
-
? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>
|
|
86
|
-
: never
|
|
87
|
-
: TPossiblyParam extends ''
|
|
88
|
-
? TAcc
|
|
89
|
-
: TPossiblyParam | TAcc
|
|
49
|
+
export type ParsePathParams<T extends string, TAcc = never> = T &
|
|
50
|
+
`${string}$${string}` extends never
|
|
51
|
+
? TAcc
|
|
52
|
+
: T extends `${string}$${infer TPossiblyParam}`
|
|
53
|
+
? TPossiblyParam extends ''
|
|
54
|
+
? TAcc
|
|
55
|
+
: TPossiblyParam & `${string}/${string}` extends never
|
|
56
|
+
? TPossiblyParam | TAcc
|
|
57
|
+
: TPossiblyParam extends `${infer TParam}/${infer TRest}`
|
|
58
|
+
? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>
|
|
59
|
+
: never
|
|
90
60
|
: TAcc
|
|
91
|
-
: TAcc
|
|
92
|
-
|
|
93
|
-
export type Join<T, TDelimiter extends string = '/'> = T extends []
|
|
94
|
-
? ''
|
|
95
|
-
: T extends [infer L extends string]
|
|
96
|
-
? L
|
|
97
|
-
: T extends [
|
|
98
|
-
infer L extends string,
|
|
99
|
-
...infer Tail extends [...Array<string>],
|
|
100
|
-
]
|
|
101
|
-
? CleanPath<`${L}${TDelimiter}${Join<Tail>}`>
|
|
102
|
-
: never
|
|
103
61
|
|
|
104
|
-
export type
|
|
105
|
-
?
|
|
106
|
-
:
|
|
62
|
+
export type AddTrailingSlash<T> = T & `${string}/` extends never
|
|
63
|
+
? `${T & string}/`
|
|
64
|
+
: T
|
|
107
65
|
|
|
108
|
-
export type
|
|
66
|
+
export type RemoveTrailingSlashes<T> = T & `${string}/` extends never
|
|
67
|
+
? T
|
|
68
|
+
: T extends `${infer R}/`
|
|
69
|
+
? R
|
|
70
|
+
: T
|
|
109
71
|
|
|
110
|
-
export type
|
|
72
|
+
export type AddLeadingSlash<T> = T & `/${string}` extends never
|
|
73
|
+
? `/${T & string}`
|
|
74
|
+
: T
|
|
111
75
|
|
|
112
|
-
export type RemoveLeadingSlashes<T> = T
|
|
76
|
+
export type RemoveLeadingSlashes<T> = T & `/${string}` extends never
|
|
77
|
+
? T
|
|
78
|
+
: T extends `/${infer R}`
|
|
79
|
+
? R
|
|
80
|
+
: T
|
|
113
81
|
|
|
114
|
-
export type
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
> extends never
|
|
119
|
-
? RouteToPath<TRouter, TRouter['routeTree']>
|
|
120
|
-
: RouteToPath<
|
|
121
|
-
TRouter,
|
|
122
|
-
RouteByPath<TRouter['routeTree'], RemoveTrailingSlashes<TSearchPath>>
|
|
123
|
-
>
|
|
82
|
+
export type FindDescendantPaths<
|
|
83
|
+
TRouter extends AnyRouter,
|
|
84
|
+
TPrefix extends string,
|
|
85
|
+
> = `${TPrefix}${string}` & RouteToPath<TRouter>
|
|
124
86
|
|
|
125
87
|
export type SearchPaths<
|
|
126
88
|
TRouter extends AnyRouter,
|
|
127
|
-
|
|
128
|
-
TPaths =
|
|
129
|
-
|
|
130
|
-
TFilteredPaths = TPaths & `${TPrefix}${string}`,
|
|
131
|
-
> = TFilteredPaths extends `${TPrefix}${infer TRest}` ? TRest : never
|
|
89
|
+
TPrefix extends string,
|
|
90
|
+
TPaths = FindDescendantPaths<TRouter, TPrefix>,
|
|
91
|
+
> = TPaths extends `${TPrefix}${infer TRest}` ? TRest : never
|
|
132
92
|
|
|
133
93
|
export type SearchRelativePathAutoComplete<
|
|
134
94
|
TRouter extends AnyRouter,
|
|
135
95
|
TTo extends string,
|
|
136
96
|
TSearchPath extends string,
|
|
137
|
-
> = `${TTo}
|
|
97
|
+
> = `${TTo}${SearchPaths<TRouter, TSearchPath>}`
|
|
138
98
|
|
|
139
99
|
export type RelativeToParentPathAutoComplete<
|
|
140
100
|
TRouter extends AnyRouter,
|
|
@@ -153,7 +113,9 @@ export type RelativeToCurrentPathAutoComplete<
|
|
|
153
113
|
TRouter extends AnyRouter,
|
|
154
114
|
TFrom extends string,
|
|
155
115
|
TTo extends string,
|
|
156
|
-
TResolvedPath extends string =
|
|
116
|
+
TResolvedPath extends string = RemoveTrailingSlashes<
|
|
117
|
+
ResolveRelativePath<TFrom, TTo>
|
|
118
|
+
>,
|
|
157
119
|
> =
|
|
158
120
|
| SearchRelativePathAutoComplete<TRouter, TTo, TResolvedPath>
|
|
159
121
|
| CurrentPath<TrailingSlashOptionByRouter<TRouter>>
|
|
@@ -166,7 +128,7 @@ export type AbsolutePathAutoComplete<
|
|
|
166
128
|
? CurrentPath<TrailingSlashOptionByRouter<TRouter>>
|
|
167
129
|
: TFrom extends `/`
|
|
168
130
|
? never
|
|
169
|
-
:
|
|
131
|
+
: FindDescendantPaths<TRouter, TFrom> extends never
|
|
170
132
|
? never
|
|
171
133
|
: CurrentPath<TrailingSlashOptionByRouter<TRouter>>)
|
|
172
134
|
| (string extends TFrom
|
|
@@ -174,7 +136,7 @@ export type AbsolutePathAutoComplete<
|
|
|
174
136
|
: TFrom extends `/`
|
|
175
137
|
? never
|
|
176
138
|
: ParentPath<TrailingSlashOptionByRouter<TRouter>>)
|
|
177
|
-
| RouteToPath<TRouter
|
|
139
|
+
| RouteToPath<TRouter>
|
|
178
140
|
| (TFrom extends '/'
|
|
179
141
|
? never
|
|
180
142
|
: string extends TFrom
|
|
@@ -185,21 +147,23 @@ export type RelativeToPathAutoComplete<
|
|
|
185
147
|
TRouter extends AnyRouter,
|
|
186
148
|
TFrom extends string,
|
|
187
149
|
TTo extends string,
|
|
188
|
-
> = string extends
|
|
189
|
-
?
|
|
190
|
-
:
|
|
191
|
-
?
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
150
|
+
> = string extends TTo
|
|
151
|
+
? string
|
|
152
|
+
: string extends TFrom
|
|
153
|
+
? AbsolutePathAutoComplete<TRouter, TFrom>
|
|
154
|
+
: TTo & `..${string}` extends never
|
|
155
|
+
? TTo & `.${string}` extends never
|
|
156
|
+
? AbsolutePathAutoComplete<TRouter, TFrom>
|
|
157
|
+
: RelativeToCurrentPathAutoComplete<
|
|
158
|
+
TRouter,
|
|
159
|
+
TFrom,
|
|
160
|
+
RemoveTrailingSlashes<TTo>
|
|
161
|
+
>
|
|
162
|
+
: RelativeToParentPathAutoComplete<
|
|
198
163
|
TRouter,
|
|
199
164
|
TFrom,
|
|
200
165
|
RemoveTrailingSlashes<TTo>
|
|
201
166
|
>
|
|
202
|
-
: AbsolutePathAutoComplete<TRouter, TFrom>
|
|
203
167
|
|
|
204
168
|
export type NavigateOptions<
|
|
205
169
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
@@ -451,33 +415,19 @@ export type ToPathOption<
|
|
|
451
415
|
TRouter extends AnyRouter = AnyRouter,
|
|
452
416
|
TFrom extends string = string,
|
|
453
417
|
TTo extends string | undefined = string,
|
|
454
|
-
> =
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
TPass,
|
|
465
|
-
TFail,
|
|
418
|
+
> = ConstrainLiteral<
|
|
419
|
+
TTo,
|
|
420
|
+
RelativeToPathAutoComplete<
|
|
421
|
+
TRouter,
|
|
422
|
+
NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',
|
|
423
|
+
NoInfer<TTo> & string
|
|
424
|
+
>
|
|
425
|
+
>
|
|
426
|
+
|
|
427
|
+
export type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<
|
|
466
428
|
TFrom,
|
|
467
|
-
>
|
|
468
|
-
|
|
469
|
-
: RouteByPath<TRouter['routeTree'], TFrom> extends never
|
|
470
|
-
? TFail
|
|
471
|
-
: TPass
|
|
472
|
-
|
|
473
|
-
export type FromPathOption<TRouter extends AnyRouter, TFrom> =
|
|
474
|
-
| CheckFromPath<
|
|
475
|
-
TRouter,
|
|
476
|
-
string extends TFrom ? TFrom & {} : TFrom,
|
|
477
|
-
never,
|
|
478
|
-
TFrom
|
|
479
|
-
>
|
|
480
|
-
| RoutePaths<TRouter['routeTree']>
|
|
429
|
+
RoutePaths<TRouter['routeTree']>
|
|
430
|
+
>
|
|
481
431
|
|
|
482
432
|
export interface ActiveOptions {
|
|
483
433
|
exact?: boolean
|
|
@@ -524,16 +474,41 @@ export interface LinkOptionsProps {
|
|
|
524
474
|
disabled?: boolean
|
|
525
475
|
}
|
|
526
476
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
477
|
+
type JoinPath<TLeft extends string, TRight extends string> = TRight extends ''
|
|
478
|
+
? TLeft
|
|
479
|
+
: TLeft extends ''
|
|
480
|
+
? TRight
|
|
481
|
+
: `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`
|
|
482
|
+
|
|
483
|
+
type RemoveLastSegment<
|
|
484
|
+
T extends string,
|
|
485
|
+
TAcc extends string = '',
|
|
486
|
+
> = T extends `${infer TSegment}/${infer TRest}`
|
|
487
|
+
? TRest & `${string}/${string}` extends never
|
|
488
|
+
? `${TAcc}${TSegment}`
|
|
489
|
+
: RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>
|
|
490
|
+
: TAcc
|
|
491
|
+
|
|
492
|
+
export type ResolveCurrentPath<TFrom, TTo> = TTo extends '.'
|
|
493
|
+
? TFrom
|
|
494
|
+
: TTo extends './'
|
|
495
|
+
? AddTrailingSlash<TFrom>
|
|
496
|
+
: TTo & `./${string}` extends never
|
|
497
|
+
? never
|
|
498
|
+
: TTo extends `./${infer TRest}`
|
|
499
|
+
? ResolveRelativePath<TFrom, TRest>
|
|
500
|
+
: never
|
|
501
|
+
|
|
502
|
+
export type ResolveParentPath<TFrom extends string, TTo> = TTo extends '../'
|
|
503
|
+
? RemoveLastSegment<TFrom>
|
|
504
|
+
: TTo & `..${string}` extends never
|
|
505
|
+
? never
|
|
506
|
+
: TTo extends `..${infer ToRest}`
|
|
507
|
+
? ResolveRelativePath<
|
|
508
|
+
RemoveLastSegment<TFrom>,
|
|
509
|
+
RemoveLeadingSlashes<ToRest>
|
|
532
510
|
>
|
|
533
|
-
|
|
534
|
-
: ResolveRoute<TRouter, TFrom, TTo> extends never
|
|
535
|
-
? TFail
|
|
536
|
-
: TPass
|
|
511
|
+
: never
|
|
537
512
|
|
|
538
513
|
export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom
|
|
539
514
|
? TTo
|
|
@@ -543,25 +518,13 @@ export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom
|
|
|
543
518
|
? TFrom
|
|
544
519
|
: TFrom extends string
|
|
545
520
|
? TTo extends string
|
|
546
|
-
? TTo extends
|
|
547
|
-
?
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
? TTo
|
|
554
|
-
: Split<TTo> extends ['..', ...infer ToRest]
|
|
555
|
-
? Split<TFrom> extends [...infer FromRest, infer FromTail]
|
|
556
|
-
? ToRest extends ['/']
|
|
557
|
-
? Join<['/', ...FromRest, '/']>
|
|
558
|
-
: ResolveRelativePath<Join<FromRest>, Join<ToRest>>
|
|
559
|
-
: never
|
|
560
|
-
: Split<TTo> extends ['.', ...infer ToRest]
|
|
561
|
-
? ToRest extends ['/']
|
|
562
|
-
? Join<[TFrom, '/']>
|
|
563
|
-
: ResolveRelativePath<TFrom, Join<ToRest>>
|
|
564
|
-
: CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>
|
|
521
|
+
? TTo & `..${string}` extends never
|
|
522
|
+
? TTo & `.${string}` extends never
|
|
523
|
+
? TTo & `/${string}` extends never
|
|
524
|
+
? AddLeadingSlash<JoinPath<TFrom, TTo>>
|
|
525
|
+
: TTo
|
|
526
|
+
: ResolveCurrentPath<TFrom, TTo>
|
|
527
|
+
: ResolveParentPath<TFrom, TTo>
|
|
565
528
|
: never
|
|
566
529
|
: never
|
|
567
530
|
|
package/src/route.ts
CHANGED
|
@@ -26,7 +26,13 @@ import type { NavigateOptions, ParsePathParams, ToMaskOptions } from './link'
|
|
|
26
26
|
import type { ParsedLocation } from './location'
|
|
27
27
|
import type { RouteById, RouteIds, RoutePaths } from './routeInfo'
|
|
28
28
|
import type { AnyRouter, RegisteredRouter, Router } from './router'
|
|
29
|
-
import type {
|
|
29
|
+
import type {
|
|
30
|
+
Assign,
|
|
31
|
+
Constrain,
|
|
32
|
+
ConstrainLiteral,
|
|
33
|
+
Expand,
|
|
34
|
+
NoInfer,
|
|
35
|
+
} from './utils'
|
|
30
36
|
import type { BuildLocationFn, NavigateFn } from './RouterProvider'
|
|
31
37
|
import type { NotFoundError } from './not-found'
|
|
32
38
|
import type { LazyRoute } from './fileRoute'
|
|
@@ -112,11 +118,12 @@ export type RouteOptions<
|
|
|
112
118
|
NoInfer<TBeforeLoadFn>
|
|
113
119
|
>
|
|
114
120
|
|
|
115
|
-
export type ParseSplatParams<TPath extends string> = TPath
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
?
|
|
119
|
-
:
|
|
121
|
+
export type ParseSplatParams<TPath extends string> = TPath &
|
|
122
|
+
`${string}$` extends never
|
|
123
|
+
? TPath & `${string}$/${string}` extends never
|
|
124
|
+
? never
|
|
125
|
+
: '_splat'
|
|
126
|
+
: '_splat'
|
|
120
127
|
|
|
121
128
|
export interface SplatParams {
|
|
122
129
|
_splat?: string
|
|
@@ -794,7 +801,7 @@ export type RouteTypesById<TRouter extends AnyRouter, TId> = RouteById<
|
|
|
794
801
|
>['types']
|
|
795
802
|
|
|
796
803
|
export function getRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter>(
|
|
797
|
-
id:
|
|
804
|
+
id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>,
|
|
798
805
|
) {
|
|
799
806
|
return new RouteApi<TId, TRouter>({ id })
|
|
800
807
|
}
|
package/src/routeInfo.ts
CHANGED
|
@@ -114,9 +114,7 @@ export type RouteToPathNeverTrailingSlash<TRoute extends AnyRoute> =
|
|
|
114
114
|
TRoute['path'] extends '/'
|
|
115
115
|
? TRoute['fullPath'] extends '/'
|
|
116
116
|
? TRoute['fullPath']
|
|
117
|
-
: TRoute['fullPath']
|
|
118
|
-
? TRest
|
|
119
|
-
: TRoute['fullPath']
|
|
117
|
+
: RemoveTrailingSlashes<TRoute['fullPath']>
|
|
120
118
|
: TRoute['fullPath']
|
|
121
119
|
|
|
122
120
|
export type RouteToPathPreserveTrailingSlash<TRoute extends AnyRoute> =
|
|
@@ -139,11 +137,9 @@ export type RouteToByRouter<
|
|
|
139
137
|
TRoute extends AnyRoute,
|
|
140
138
|
> = RouteToPathByTrailingSlashOption<TRoute>[TrailingSlashOptionByRouter<TRouter>]
|
|
141
139
|
|
|
142
|
-
export type CodeRouteToPath<
|
|
143
|
-
TRouter extends
|
|
144
|
-
|
|
145
|
-
> =
|
|
146
|
-
ParseRouteWithoutBranches<TRouteTree> extends infer TRoute extends AnyRoute
|
|
140
|
+
export type CodeRouteToPath<TRouter extends AnyRouter> =
|
|
141
|
+
ParseRouteWithoutBranches<TRouter['routeTree']> extends infer TRoute extends
|
|
142
|
+
AnyRoute
|
|
147
143
|
? TRoute extends any
|
|
148
144
|
? RouteToByRouter<TRouter, TRoute>
|
|
149
145
|
: never
|
|
@@ -159,13 +155,10 @@ export type FileRouteToPath<
|
|
|
159
155
|
? AddTrailingSlash<TTo>
|
|
160
156
|
: TTo | AddTrailingSlash<TTo>
|
|
161
157
|
|
|
162
|
-
export type RouteToPath<
|
|
163
|
-
TRouter extends AnyRouter,
|
|
164
|
-
TRouteTree extends AnyRoute,
|
|
165
|
-
> = unknown extends TRouter
|
|
158
|
+
export type RouteToPath<TRouter extends AnyRouter> = unknown extends TRouter
|
|
166
159
|
? string
|
|
167
160
|
: InferFileRouteTypes<TRouter['routeTree']> extends never
|
|
168
|
-
? CodeRouteToPath<TRouter
|
|
161
|
+
? CodeRouteToPath<TRouter>
|
|
169
162
|
: FileRouteToPath<TRouter>
|
|
170
163
|
|
|
171
164
|
export type CodeRoutesByToPath<TRouter extends AnyRouter> =
|
package/src/router.ts
CHANGED
|
@@ -1058,6 +1058,7 @@ export class Router<
|
|
|
1058
1058
|
|
|
1059
1059
|
parseLocation = (
|
|
1060
1060
|
previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>,
|
|
1061
|
+
locationToParse?: HistoryLocation,
|
|
1061
1062
|
): ParsedLocation<FullSearchSchema<TRouteTree>> => {
|
|
1062
1063
|
const parse = ({
|
|
1063
1064
|
pathname,
|
|
@@ -1078,7 +1079,7 @@ export class Router<
|
|
|
1078
1079
|
}
|
|
1079
1080
|
}
|
|
1080
1081
|
|
|
1081
|
-
const location = parse(this.history.location)
|
|
1082
|
+
const location = parse(locationToParse ?? this.history.location)
|
|
1082
1083
|
|
|
1083
1084
|
const { __tempLocation, __tempKey } = location.state
|
|
1084
1085
|
|
|
@@ -2552,37 +2553,7 @@ export class Router<
|
|
|
2552
2553
|
|
|
2553
2554
|
// Actually run the loader and handle the result
|
|
2554
2555
|
try {
|
|
2555
|
-
|
|
2556
|
-
if (route.lazyFn) {
|
|
2557
|
-
route._lazyPromise = route
|
|
2558
|
-
.lazyFn()
|
|
2559
|
-
.then((lazyRoute) => {
|
|
2560
|
-
// explicitly don't copy over the lazy route's id
|
|
2561
|
-
const { id: _id, ...options } =
|
|
2562
|
-
lazyRoute.options
|
|
2563
|
-
Object.assign(route.options, options)
|
|
2564
|
-
})
|
|
2565
|
-
} else {
|
|
2566
|
-
route._lazyPromise = Promise.resolve()
|
|
2567
|
-
}
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
-
// If for some reason lazy resolves more lazy components...
|
|
2571
|
-
// We'll wait for that before pre attempt to preload any
|
|
2572
|
-
// components themselves.
|
|
2573
|
-
if (route._componentsPromise === undefined) {
|
|
2574
|
-
route._componentsPromise = route._lazyPromise.then(
|
|
2575
|
-
() =>
|
|
2576
|
-
Promise.all(
|
|
2577
|
-
componentTypes.map(async (type) => {
|
|
2578
|
-
const component = route.options[type]
|
|
2579
|
-
if ((component as any)?.preload) {
|
|
2580
|
-
await (component as any).preload()
|
|
2581
|
-
}
|
|
2582
|
-
}),
|
|
2583
|
-
),
|
|
2584
|
-
)
|
|
2585
|
-
}
|
|
2556
|
+
this.loadRouteChunk(route)
|
|
2586
2557
|
|
|
2587
2558
|
updateMatch(matchId, (prev) => ({
|
|
2588
2559
|
...prev,
|
|
@@ -2820,6 +2791,37 @@ export class Router<
|
|
|
2820
2791
|
this.clearCache({ filter })
|
|
2821
2792
|
}
|
|
2822
2793
|
|
|
2794
|
+
loadRouteChunk = (route: AnyRoute) => {
|
|
2795
|
+
if (route._lazyPromise === undefined) {
|
|
2796
|
+
if (route.lazyFn) {
|
|
2797
|
+
route._lazyPromise = route.lazyFn().then((lazyRoute) => {
|
|
2798
|
+
// explicitly don't copy over the lazy route's id
|
|
2799
|
+
const { id: _id, ...options } = lazyRoute.options
|
|
2800
|
+
Object.assign(route.options, options)
|
|
2801
|
+
})
|
|
2802
|
+
} else {
|
|
2803
|
+
route._lazyPromise = Promise.resolve()
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
// If for some reason lazy resolves more lazy components...
|
|
2808
|
+
// We'll wait for that before pre attempt to preload any
|
|
2809
|
+
// components themselves.
|
|
2810
|
+
if (route._componentsPromise === undefined) {
|
|
2811
|
+
route._componentsPromise = route._lazyPromise.then(() =>
|
|
2812
|
+
Promise.all(
|
|
2813
|
+
componentTypes.map(async (type) => {
|
|
2814
|
+
const component = route.options[type]
|
|
2815
|
+
if ((component as any)?.preload) {
|
|
2816
|
+
await (component as any).preload()
|
|
2817
|
+
}
|
|
2818
|
+
}),
|
|
2819
|
+
),
|
|
2820
|
+
)
|
|
2821
|
+
}
|
|
2822
|
+
return route._componentsPromise
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2823
2825
|
preloadRoute = async <
|
|
2824
2826
|
TFrom extends RoutePaths<TRouteTree> | string = string,
|
|
2825
2827
|
TTo extends string | undefined = undefined,
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FromPathOption,
|
|
3
|
+
NavigateOptions,
|
|
4
|
+
PathParamOptions,
|
|
5
|
+
SearchParamOptions,
|
|
6
|
+
ToPathOption,
|
|
7
|
+
} from './link'
|
|
8
|
+
import type { RouteIds } from './routeInfo'
|
|
9
|
+
import type { AnyRouter, RegisteredRouter } from './router'
|
|
10
|
+
import type { UseParamsOptions, UseParamsResult } from './useParams'
|
|
11
|
+
import type { UseSearchOptions, UseSearchResult } from './useSearch'
|
|
12
|
+
import type { Constrain, ConstrainLiteral } from './utils'
|
|
13
|
+
|
|
14
|
+
export type ValidateFromPath<
|
|
15
|
+
TFrom,
|
|
16
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
17
|
+
> = FromPathOption<TRouter, TFrom>
|
|
18
|
+
|
|
19
|
+
export type ValidateToPath<
|
|
20
|
+
TTo extends string | undefined,
|
|
21
|
+
TFrom extends string = string,
|
|
22
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
23
|
+
> = ToPathOption<TRouter, TFrom, TTo>
|
|
24
|
+
|
|
25
|
+
export type ValidateSearch<
|
|
26
|
+
TTo extends string | undefined,
|
|
27
|
+
TFrom extends string = string,
|
|
28
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
29
|
+
> = SearchParamOptions<TRouter, TFrom, TTo>
|
|
30
|
+
|
|
31
|
+
export type ValidateParams<
|
|
32
|
+
TTo extends string | undefined,
|
|
33
|
+
TFrom extends string = string,
|
|
34
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
35
|
+
> = PathParamOptions<TRouter, TFrom, TTo>
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export type InferFrom<TOptions> = TOptions extends {
|
|
41
|
+
from: infer TFrom extends string
|
|
42
|
+
}
|
|
43
|
+
? TFrom
|
|
44
|
+
: string
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export type InferTo<TOptions> = TOptions extends {
|
|
50
|
+
to: infer TTo extends string
|
|
51
|
+
}
|
|
52
|
+
? TTo
|
|
53
|
+
: undefined
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export type InferMaskTo<TOptions> = TOptions extends {
|
|
59
|
+
mask: { to: infer TTo extends string }
|
|
60
|
+
}
|
|
61
|
+
? TTo
|
|
62
|
+
: string
|
|
63
|
+
|
|
64
|
+
export type InferMaskFrom<TOptions> = TOptions extends {
|
|
65
|
+
mask: { from: infer TFrom extends string }
|
|
66
|
+
}
|
|
67
|
+
? TFrom
|
|
68
|
+
: string
|
|
69
|
+
|
|
70
|
+
export type ValidateNavigateOptions<
|
|
71
|
+
TOptions,
|
|
72
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
73
|
+
> = Constrain<
|
|
74
|
+
TOptions,
|
|
75
|
+
NavigateOptions<
|
|
76
|
+
TRouter,
|
|
77
|
+
InferFrom<TOptions>,
|
|
78
|
+
InferTo<TOptions>,
|
|
79
|
+
InferMaskFrom<TOptions>,
|
|
80
|
+
InferMaskTo<TOptions>
|
|
81
|
+
>
|
|
82
|
+
>
|
|
83
|
+
|
|
84
|
+
export type ValidateNavigateOptionsArray<TOptions extends ReadonlyArray<any>> =
|
|
85
|
+
{ [K in keyof TOptions]: ValidateNavigateOptions<TOptions[K]> }
|
|
86
|
+
|
|
87
|
+
export type ValidateId<
|
|
88
|
+
TId extends string,
|
|
89
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
90
|
+
> = ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
export type InferStrict<TOptions> = TOptions extends {
|
|
96
|
+
strict: infer TStrict extends boolean
|
|
97
|
+
}
|
|
98
|
+
? TStrict
|
|
99
|
+
: true
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
export type InferSelected<TOptions> = TOptions extends {
|
|
105
|
+
select: (...args: Array<any>) => infer TSelected
|
|
106
|
+
}
|
|
107
|
+
? TSelected
|
|
108
|
+
: unknown
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
export type InferStructuralSharing<TOptions> = TOptions extends {
|
|
114
|
+
structuralSharing: infer TStructuralSharing
|
|
115
|
+
}
|
|
116
|
+
? TStructuralSharing
|
|
117
|
+
: unknown
|
|
118
|
+
|
|
119
|
+
export type ValidateUseSearchOptions<
|
|
120
|
+
TOptions,
|
|
121
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
122
|
+
> = Constrain<
|
|
123
|
+
TOptions,
|
|
124
|
+
UseSearchOptions<
|
|
125
|
+
TRouter,
|
|
126
|
+
InferFrom<TOptions>,
|
|
127
|
+
InferStrict<TOptions>,
|
|
128
|
+
InferSelected<TOptions>,
|
|
129
|
+
InferStructuralSharing<TOptions>
|
|
130
|
+
>
|
|
131
|
+
>
|
|
132
|
+
|
|
133
|
+
export type ValidateUseSearchResult<
|
|
134
|
+
TOptions,
|
|
135
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
136
|
+
> = UseSearchResult<
|
|
137
|
+
TRouter,
|
|
138
|
+
InferFrom<TOptions>,
|
|
139
|
+
InferStrict<TOptions>,
|
|
140
|
+
InferSelected<TOptions>
|
|
141
|
+
>
|
|
142
|
+
|
|
143
|
+
export type ValidateUseParamsOptions<
|
|
144
|
+
TOptions,
|
|
145
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
146
|
+
> = Constrain<
|
|
147
|
+
TOptions,
|
|
148
|
+
UseParamsOptions<
|
|
149
|
+
TRouter,
|
|
150
|
+
InferFrom<TOptions>,
|
|
151
|
+
InferStrict<TOptions>,
|
|
152
|
+
InferSelected<TOptions>,
|
|
153
|
+
InferSelected<TOptions>
|
|
154
|
+
>
|
|
155
|
+
>
|
|
156
|
+
|
|
157
|
+
export type ValidateUseParamsResult<
|
|
158
|
+
TOptions,
|
|
159
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
160
|
+
> = Constrain<
|
|
161
|
+
TOptions,
|
|
162
|
+
UseParamsResult<
|
|
163
|
+
TRouter,
|
|
164
|
+
InferFrom<TOptions>,
|
|
165
|
+
InferStrict<TOptions>,
|
|
166
|
+
InferSelected<TOptions>
|
|
167
|
+
>
|
|
168
|
+
>
|