@@ -19,6 +19,7 @@ import {
19
19
PickRequired ,
20
20
UnionToIntersection ,
21
21
Updater ,
22
+ WithoutEmpty ,
22
23
deepEqual ,
23
24
functionalUpdate ,
24
25
} from './utils'
@@ -116,10 +117,10 @@ export type RelativeToPathAutoComplete<
116
117
117
118
export type NavigateOptions <
118
119
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
119
- TFrom extends RoutePaths < TRouteTree > = '/' ,
120
- TTo extends string = '' ,
121
- TMaskFrom extends RoutePaths < TRouteTree > = TFrom ,
122
- TMaskTo extends string = '' ,
120
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
121
+ TTo extends string | undefined = undefined ,
122
+ TMaskFrom extends RoutePaths < TRouteTree > | string = TFrom ,
123
+ TMaskTo extends string | undefined = undefined ,
123
124
> = ToOptions < TRouteTree , TFrom , TTo , TMaskFrom , TMaskTo > & {
124
125
// `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
125
126
replace ?: boolean
@@ -130,26 +131,26 @@ export type NavigateOptions<
130
131
131
132
export type ToOptions <
132
133
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
133
- TFrom extends RoutePaths < TRouteTree > = '/' ,
134
- TTo extends string = '' ,
135
- TMaskFrom extends RoutePaths < TRouteTree > = '/' ,
136
- TMaskTo extends string = '' ,
134
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
135
+ TTo extends string | undefined = undefined ,
136
+ TMaskFrom extends RoutePaths < TRouteTree > | string = TFrom ,
137
+ TMaskTo extends string | undefined = undefined ,
137
138
> = ToSubOptions < TRouteTree , TFrom , TTo > & {
138
139
mask ?: ToMaskOptions < TRouteTree , TMaskFrom , TMaskTo >
139
140
}
140
141
141
142
export type ToMaskOptions <
142
143
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
143
- TMaskFrom extends RoutePaths < TRouteTree > = '/' ,
144
- TMaskTo extends string = '' ,
144
+ TMaskFrom extends RoutePaths < TRouteTree > | string = string ,
145
+ TMaskTo extends string | undefined = undefined ,
145
146
> = ToSubOptions < TRouteTree , TMaskFrom , TMaskTo > & {
146
147
unmaskOnReload ?: boolean
147
148
}
148
149
149
150
export type ToSubOptions <
150
151
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
151
- TFrom extends RoutePaths < TRouteTree > = '/' ,
152
- TTo extends string = '' ,
152
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
153
+ TTo extends string | undefined = undefined ,
153
154
TResolved = ResolveRelativePath < TFrom , NoInfer < TTo > > ,
154
155
> = {
155
156
to ?: ToPathOption < TRouteTree , TFrom , TTo >
@@ -162,72 +163,56 @@ export type ToSubOptions<
162
163
// // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
163
164
} & CheckPath < TRouteTree , NoInfer < TResolved > , { } > &
164
165
SearchParamOptions < TRouteTree , TFrom , TTo , TResolved > &
165
- PathParamOptions < TRouteTree , TFrom , TResolved >
166
+ PathParamOptions < TRouteTree , TFrom , TTo , TResolved >
166
167
167
- export type SearchParamOptions <
168
+ type ParamsReducer < TFrom , TTo > = TTo | ( ( current : TFrom ) => TTo )
169
+
170
+ export type ParamOptions <
168
171
TRouteTree extends AnyRoute ,
169
172
TFrom ,
170
173
TTo ,
171
- TResolved = ResolveRelativePath < TFrom , NoInfer < TTo > > ,
172
- TFromSearchEnsured = '/' extends TFrom
173
- ? FullSearchSchema < TRouteTree >
174
- : Expand <
175
- PickRequired <
176
- RouteByPath < TRouteTree , TFrom > [ 'types' ] [ 'fullSearchSchema' ]
177
- >
178
- > ,
179
- TFromSearchOptional = Omit <
180
- FullSearchSchema < TRouteTree > ,
181
- keyof TFromSearchEnsured
182
- > ,
183
- TFromSearch = Expand < TFromSearchEnsured & TFromSearchOptional > ,
184
- TToSearch = '' extends TTo
185
- ? FullSearchSchema < TRouteTree >
186
- : Expand < RouteByPath < TRouteTree , TResolved > [ 'types' ] [ 'fullSearchSchema' ] > ,
187
- > = keyof PickRequired < TToSearch > extends never
188
- ? {
189
- search ?: true | SearchReducer < TFromSearch , TToSearch >
190
- }
191
- : {
192
- search : TFromSearchEnsured extends PickRequired < TToSearch >
193
- ? true | SearchReducer < TFromSearch , TToSearch >
194
- : SearchReducer < TFromSearch , TToSearch >
195
- }
174
+ TResolved ,
175
+ TParamVariant extends 'allParams' | 'fullSearchSchema' ,
176
+ TFromParams = Expand < RouteByPath < TRouteTree , TFrom > [ 'types' ] [ TParamVariant ] > ,
177
+ TToParams = TTo extends undefined
178
+ ? TFromParams
179
+ : never extends TResolved
180
+ ? Expand < RouteByPath < TRouteTree , TTo > [ 'types' ] [ TParamVariant ] >
181
+ : Expand < RouteByPath < TRouteTree , TResolved > [ 'types' ] [ TParamVariant ] > ,
182
+ TReducer = ParamsReducer < TFromParams , TToParams > ,
183
+ > = Expand < WithoutEmpty < PickRequired < TToParams > > > extends never
184
+ ? Partial < MakeParamOption < TParamVariant , true | TReducer > >
185
+ : TFromParams extends Expand < WithoutEmpty < PickRequired < TToParams > > >
186
+ ? MakeParamOption < TParamVariant , true | TReducer >
187
+ : MakeParamOption < TParamVariant , TReducer >
188
+
189
+ type MakeParamOption <
190
+ TParamVariant extends 'allParams' | 'fullSearchSchema' ,
191
+ T ,
192
+ > = TParamVariant extends 'allParams'
193
+ ? MakePathParamOptions < T >
194
+ : MakeSearchParamOptions < T >
195
+ type MakeSearchParamOptions < T > = { search : T }
196
+ type MakePathParamOptions < T > = { params : T }
196
197
197
- type SearchReducer < TFrom , TTo > = TTo | ( ( current : TFrom ) => TTo )
198
+ export type SearchParamOptions <
199
+ TRouteTree extends AnyRoute ,
200
+ TFrom ,
201
+ TTo ,
202
+ TResolved ,
203
+ > = ParamOptions < TRouteTree , TFrom , TTo , TResolved , 'fullSearchSchema' >
198
204
199
205
export type PathParamOptions <
200
206
TRouteTree extends AnyRoute ,
201
207
TFrom ,
202
208
TTo ,
203
- TFromParamsEnsured = Expand <
204
- UnionToIntersection <
205
- PickRequired < RouteByPath < TRouteTree , TFrom > [ 'types' ] [ 'allParams' ] >
206
- >
207
- > ,
208
- TFromParamsOptional = Omit < AllParams < TRouteTree > , keyof TFromParamsEnsured > ,
209
- TFromParams = Expand < TFromParamsOptional & TFromParamsEnsured > ,
210
- TToParams = Expand < RouteByPath < TRouteTree , TTo > [ 'types' ] [ 'allParams' ] > ,
211
- > = never extends TToParams
212
- ? {
213
- params ?: true | ParamsReducer < Partial < TFromParams > , Partial < TFromParams > >
214
- }
215
- : keyof PickRequired < TToParams > extends never
216
- ? {
217
- params ?: true | ParamsReducer < TFromParams , TToParams >
218
- }
219
- : {
220
- params : TFromParamsEnsured extends PickRequired < TToParams >
221
- ? true | ParamsReducer < TFromParams , TToParams >
222
- : ParamsReducer < TFromParams , TToParams >
223
- }
224
-
225
- type ParamsReducer < TFrom , TTo > = TTo | ( ( current : TFrom ) => TTo )
209
+ TResolved ,
210
+ > = ParamOptions < TRouteTree , TFrom , TTo , TResolved , 'allParams' >
226
211
227
212
export type ToPathOption <
228
213
TRouteTree extends AnyRoute = AnyRoute ,
229
- TFrom extends RoutePaths < TRouteTree > = '/' ,
230
- TTo extends string = '' ,
214
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
215
+ TTo extends string | undefined = undefined ,
231
216
> =
232
217
| TTo
233
218
| RelativeToPathAutoComplete <
@@ -238,8 +223,8 @@ export type ToPathOption<
238
223
239
224
export type ToIdOption <
240
225
TRouteTree extends AnyRoute = AnyRoute ,
241
- TFrom extends RoutePaths < TRouteTree > = '/' ,
242
- TTo extends string = '' ,
226
+ TFrom extends RoutePaths < TRouteTree > | undefined = undefined ,
227
+ TTo extends string | undefined = undefined ,
243
228
> =
244
229
| TTo
245
230
| RelativeToPathAutoComplete <
@@ -256,10 +241,10 @@ export interface ActiveOptions {
256
241
257
242
export type LinkOptions <
258
243
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
259
- TFrom extends RoutePaths < TRouteTree > = '/' ,
260
- TTo extends string = '' ,
261
- TMaskFrom extends RoutePaths < TRouteTree > = TFrom ,
262
- TMaskTo extends string = '' ,
244
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
245
+ TTo extends string | undefined = undefined ,
246
+ TMaskFrom extends RoutePaths < TRouteTree > | string = TFrom ,
247
+ TMaskTo extends string | undefined = undefined ,
263
248
> = NavigateOptions < TRouteTree , TFrom , TTo , TMaskFrom , TMaskTo > & {
264
249
// The standard anchor tag target attribute
265
250
target ?: HTMLAnchorElement [ 'target' ]
@@ -348,20 +333,13 @@ const preloadWarning = 'Error preloading route! ☝️'
348
333
349
334
export function useLinkProps <
350
335
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
351
- TFrom extends RoutePaths < TRouteTree > = '/' ,
352
- TTo extends string = '' ,
353
- TMaskFrom extends RoutePaths < TRouteTree > = '/' ,
354
- TMaskTo extends string = '' ,
355
- > ( {
356
- from,
357
- ...options
358
- } : UseLinkPropsOptions <
359
- TRouteTree ,
360
- TFrom ,
361
- TTo ,
362
- TMaskFrom ,
363
- TMaskTo
364
- > ) : React . AnchorHTMLAttributes < HTMLAnchorElement > {
336
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
337
+ TTo extends string | undefined = undefined ,
338
+ TMaskFrom extends RoutePaths < TRouteTree > | string = TFrom ,
339
+ TMaskTo extends string | undefined = undefined ,
340
+ > (
341
+ options : UseLinkPropsOptions < TRouteTree , TFrom , TTo , TMaskFrom , TMaskTo > ,
342
+ ) : React . AnchorHTMLAttributes < HTMLAnchorElement > {
365
343
const router = useRouter ( )
366
344
const matchPathname = useMatch ( {
367
345
strict : false ,
@@ -574,10 +552,10 @@ export function useLinkProps<
574
552
export interface LinkComponent < TProps extends Record < string , any > = { } > {
575
553
<
576
554
TRouteTree extends AnyRoute = RegisteredRouter [ 'routeTree' ] ,
577
- TFrom extends RoutePaths < TRouteTree > = '/' ,
578
- TTo extends string = '' ,
579
- TMaskFrom extends RoutePaths < TRouteTree > = '/' ,
580
- TMaskTo extends string = '' ,
555
+ TFrom extends RoutePaths < TRouteTree > | string = string ,
556
+ TTo extends string | undefined = undefined ,
557
+ TMaskFrom extends RoutePaths < TRouteTree > | string = TFrom ,
558
+ TMaskTo extends string | undefined = undefined ,
581
559
> (
582
560
props : LinkProps < TRouteTree , TFrom , TTo , TMaskFrom , TMaskTo > &
583
561
TProps &
0 commit comments