Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

link.ts

706 lines22.6 KB

1import type { HistoryState, ParsedHistoryState } from '@tanstack/history'
2import type {
3 AllParams,
4 CatchAllPaths,
5 CurrentPath,
6 FullSearchSchema,
7 FullSearchSchemaInput,
8 ParentPath,
9 RouteByPath,
10 RouteByToPath,
11 RoutePaths,
12 RouteToPath,
13 ToPath,
14} from './routeInfo'
15import type {
16 AnyRouter,
17 RegisteredRouter,
18 ViewTransitionOptions,
19} from './router'
20import type {
21 ConstrainLiteral,
22 Expand,
23 MakeDifferenceOptional,
24 NoInfer,
25 NonNullableUpdater,
26 Updater,
27} from './utils'
28import type { ParsedLocation } from './location'
29​
30export type IsRequiredParams<TParams> =
31 Record<never, never> extends TParams ? never : true
32​
33export interface ParsePathParamsResult<
34 in out TRequired,
35 in out TOptional,
36 in out TRest,
37> {
38 required: TRequired
39 optional: TOptional
40 rest: TRest
42​
43export type AnyParsePathParamsResult = ParsePathParamsResult<
44 string,
45 string,
46 string
48​
49export type ParsePathParamsBoundaryStart<T extends string> =
50 T extends `${infer TLeft}{-${infer TRight}`
51 ? ParsePathParamsResult<
52 ParsePathParams<TLeft>['required'],
53 | ParsePathParams<TLeft>['optional']
54 | ParsePathParams<TRight>['required']
55 | ParsePathParams<TRight>['optional'],
56 ParsePathParams<TRight>['rest']
57 >
58 : T extends `${infer TLeft}{${infer TRight}`
59 ? ParsePathParamsResult<
60 | ParsePathParams<TLeft>['required']
61 | ParsePathParams<TRight>['required'],
62 | ParsePathParams<TLeft>['optional']
63 | ParsePathParams<TRight>['optional'],
64 ParsePathParams<TRight>['rest']
65 >
66 : never
67​
68export type ParsePathParamsSymbol<T extends string> =
69 T extends `${string}$${infer TRight}`
70 ? TRight extends `${string}/${string}`
71 ? TRight extends `${infer TParam}/${infer TRest}`
72 ? TParam extends ''
73 ? ParsePathParamsResult<
74 ParsePathParams<TRest>['required'],
75 '_splat' | ParsePathParams<TRest>['optional'],
76 ParsePathParams<TRest>['rest']
77 >
78 : ParsePathParamsResult<
79 TParam | ParsePathParams<TRest>['required'],
80 ParsePathParams<TRest>['optional'],
81 ParsePathParams<TRest>['rest']
82 >
83 : never
84 : TRight extends ''
85 ? ParsePathParamsResult<never, '_splat', never>
86 : ParsePathParamsResult<TRight, never, never>
87 : never
88​
89export type ParsePathParamsBoundaryEnd<T extends string> =
90 T extends `${infer TLeft}}${infer TRight}`
91 ? ParsePathParamsResult<
92 | ParsePathParams<TLeft>['required']
93 | ParsePathParams<TRight>['required'],
94 | ParsePathParams<TLeft>['optional']
95 | ParsePathParams<TRight>['optional'],
96 ParsePathParams<TRight>['rest']
97 >
98 : never
99​
100export type ParsePathParamsEscapeStart<T extends string> =
101 T extends `${infer TLeft}[${infer TRight}`
102 ? ParsePathParamsResult<
103 | ParsePathParams<TLeft>['required']
104 | ParsePathParams<TRight>['required'],
105 | ParsePathParams<TLeft>['optional']
106 | ParsePathParams<TRight>['optional'],
107 ParsePathParams<TRight>['rest']
108 >
109 : never
110​
111export type ParsePathParamsEscapeEnd<T extends string> =
112 T extends `${string}]${infer TRight}` ? ParsePathParams<TRight> : never
113​
114export type ParsePathParams<T extends string> = T extends `${string}[${string}`
115 ? ParsePathParamsEscapeStart<T>
116 : T extends `${string}]${string}`
117 ? ParsePathParamsEscapeEnd<T>
118 : T extends `${string}}${string}`
119 ? ParsePathParamsBoundaryEnd<T>
120 : T extends `${string}{${string}`
121 ? ParsePathParamsBoundaryStart<T>
122 : T extends `${string}$${string}`
123 ? ParsePathParamsSymbol<T>
124 : never
125​
126export type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`
127​
128export type RemoveTrailingSlashes<T> = T & `${string}/` extends never
129 ? T
130 : T extends `${infer R}/`
131 ? R
132 : T
133​
134export type AddLeadingSlash<T> = T & `/${string}` extends never
135 ? `/${T & string}`
136 : T
137​
138export type RemoveLeadingSlashes<T> = T & `/${string}` extends never
139 ? T
140 : T extends `/${infer R}`
141 ? R
142 : T
143​
144type JoinPath<TLeft extends string, TRight extends string> = TRight extends ''
145 ? TLeft
146 : TLeft extends ''
147 ? TRight
148 : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`
149​
150type RemoveLastSegment<
151 T extends string,
152 TAcc extends string = '',
153> = T extends `${infer TSegment}/${infer TRest}`
154 ? TRest & `${string}/${string}` extends never
155 ? TRest extends ''
156 ? TAcc
157 : `${TAcc}${TSegment}`
158 : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>
159 : TAcc
160​
161export type ResolveCurrentPath<
162 TFrom extends string,
163 TTo extends string,
164> = TTo extends '.'
165 ? TFrom
166 : TTo extends './'
167 ? AddTrailingSlash<TFrom>
168 : TTo & `./${string}` extends never
169 ? never
170 : TTo extends `./${infer TRest}`
171 ? AddLeadingSlash<JoinPath<TFrom, TRest>>
172 : never
173​
174export type ResolveParentPath<
175 TFrom extends string,
176 TTo extends string,
177> = TTo extends '../' | '..'
178 ? TFrom extends '' | '/'
179 ? never
180 : AddLeadingSlash<RemoveLastSegment<TFrom>>
181 : TTo & `../${string}` extends never
182 ? AddLeadingSlash<JoinPath<TFrom, TTo>>
183 : TFrom extends '' | '/'
184 ? never
185 : TTo extends `../${infer ToRest}`
186 ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>
187 : AddLeadingSlash<JoinPath<TFrom, TTo>>
188​
189export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom
190 ? TTo
191 : string extends TTo
192 ? TFrom
193 : undefined extends TTo
194 ? TFrom
195 : TTo extends string
196 ? TFrom extends string
197 ? TTo extends `/${string}`
198 ? TTo
199 : TTo extends `..${string}`
200 ? ResolveParentPath<TFrom, TTo>
201 : TTo extends `.${string}`
202 ? ResolveCurrentPath<TFrom, TTo>
203 : AddLeadingSlash<JoinPath<TFrom, TTo>>
204 : never
205 : never
206​
207export type FindDescendantToPaths<
208 TRouter extends AnyRouter,
209 TPrefix extends string,
210> = `${TPrefix}/${string}` & RouteToPath<TRouter>
211​
212export type InferDescendantToPaths<
213 TRouter extends AnyRouter,
214 TPrefix extends string,
215 TPaths = FindDescendantToPaths<TRouter, TPrefix>,
216> = TPaths extends `${TPrefix}/`
217 ? never
218 : TPaths extends `${TPrefix}/${infer TRest}`
219 ? TRest
220 : never
221​
222export type RelativeToPath<
223 TRouter extends AnyRouter,
224 TTo extends string,
225 TResolvedPath extends string,
226> =
227 | (TResolvedPath & RouteToPath<TRouter> extends never
228 ? never
229 : ToPath<TRouter, TTo>)
230 | `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`
231​
232export type RelativeToParentPath<
233 TRouter extends AnyRouter,
234 TFrom extends string,
235 TTo extends string,
236 TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,
237> =
238 | RelativeToPath<TRouter, TTo, TResolvedPath>
239 | (TTo extends `${string}..` | `${string}../`
240 ? TResolvedPath extends '/' | ''
241 ? never
242 : FindDescendantToPaths<
243 TRouter,
244 RemoveTrailingSlashes<TResolvedPath>
245 > extends never
246 ? never
247 : `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}`
248 : never)
249​
250export type RelativeToCurrentPath<
251 TRouter extends AnyRouter,
252 TFrom extends string,
253 TTo extends string,
254 TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,
255> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>
256​
257export type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> =
258 | (string extends TFrom
259 ? CurrentPath<TRouter>
260 : TFrom extends `/`
261 ? never
262 : CurrentPath<TRouter>)
263 | (string extends TFrom
264 ? ParentPath<TRouter>
265 : TFrom extends `/`
266 ? never
267 : ParentPath<TRouter>)
268 | RouteToPath<TRouter>
269 | (TFrom extends '/'
270 ? never
271 : string extends TFrom
272 ? never
273 : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>)
274​
275export type RelativeToPathAutoComplete<
276 TRouter extends AnyRouter,
277 TFrom extends string,
278 TTo extends string,
279> = string extends TTo
280 ? string
281 : string extends TFrom
282 ? AbsoluteToPath<TRouter, TFrom>
283 : TTo & `..${string}` extends never
284 ? TTo & `.${string}` extends never
285 ? AbsoluteToPath<TRouter, TFrom>
286 : RelativeToCurrentPath<TRouter, TFrom, TTo>
287 : RelativeToParentPath<TRouter, TFrom, TTo>
288​
289export type NavigateOptions<
290 TRouter extends AnyRouter = RegisteredRouter,
291 TFrom extends string = string,
292 TTo extends string | undefined = '.',
293 TMaskFrom extends string = TFrom,
294 TMaskTo extends string = '.',
295> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps
296​
297/**
298 * The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.
299 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)
300 */
301export interface NavigateOptionProps {
302 /**
303 * If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.
304 * If set to `false`, the router will not scroll the element with an id matching the hash into view.
305 * If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.
306 * @default true
307 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)
308 * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
309 */
310 hashScrollIntoView?: boolean | ScrollIntoViewOptions
311 /**
312 * `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
313 * @default false
314 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)
315 */
316 replace?: boolean
317 /**
318 * Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.
319 * If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.
320 * @default true
321 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)
322 */
323 resetScroll?: boolean
324 /** @deprecated All navigations now use startTransition under the hood */
325 startTransition?: boolean
326 /**
327 * If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.
328 * If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`
329 * where `types` will be the strings array passed with `ViewTransitionOptions["types"]`.
330 * If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.
331 *
332 * If the browser does not support this api, this option will be ignored.
333 * @default false
334 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)
335 * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)
336 * @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)
337 */
338 viewTransition?: boolean | ViewTransitionOptions
339 /**
340 * If `true`, navigation will ignore any blockers that might prevent it.
341 * @default false
342 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)
343 */
344 ignoreBlocker?: boolean
345 /**
346 * If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.
347 * @default false
348 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)
349 */
350 reloadDocument?: boolean
351 /**
352 * This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.
353 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)
354 */
355 href?: string
356 /** @internal */
357 publicHref?: string
359​
360export type ToOptions<
361 TRouter extends AnyRouter = RegisteredRouter,
362 TFrom extends string = string,
363 TTo extends string | undefined = '.',
364 TMaskFrom extends string = TFrom,
365 TMaskTo extends string = '.',
366> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>
367​
368export interface MaskOptions<
369 in out TRouter extends AnyRouter,
370 in out TMaskFrom extends string,
371 in out TMaskTo extends string,
372> {
373 _fromLocation?: ParsedLocation
374 mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>
376​
377export type ToMaskOptions<
378 TRouter extends AnyRouter = RegisteredRouter,
379 TMaskFrom extends string = string,
380 TMaskTo extends string = '.',
381> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {
382 unmaskOnReload?: boolean
384​
385export type ToSubOptions<
386 TRouter extends AnyRouter = RegisteredRouter,
387 TFrom extends string = string,
388 TTo extends string | undefined = '.',
389> = ToSubOptionsProps<TRouter, TFrom, TTo> &
390 SearchParamOptions<TRouter, TFrom, TTo> &
391 PathParamOptions<TRouter, TFrom, TTo>
392​
393export interface RequiredToOptions<
394 in out TRouter extends AnyRouter,
395 in out TFrom extends string,
396 in out TTo extends string | undefined,
397> {
398 /**
399 * The internal route path to navigate to. This should be a relative or absolute path within your application.
400 * For external URLs, use the `href` property instead.
401 * @example "/dashboard" or "../profile"
402 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)
403 */
404 to: ToPathOption<TRouter, TFrom, TTo> & {}
406​
407export interface OptionalToOptions<
408 in out TRouter extends AnyRouter,
409 in out TFrom extends string,
410 in out TTo extends string | undefined,
411> {
412 /**
413 * The internal route path to navigate to. This should be a relative or absolute path within your application.
414 * For external URLs, use the `href` property instead.
415 * @example "/dashboard" or "../profile"
416 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)
417 */
418 to?: ToPathOption<TRouter, TFrom, TTo> & {}
420​
421export type MakeToRequired<
422 TRouter extends AnyRouter,
423 TFrom extends string,
424 TTo extends string | undefined,
425> = string extends TFrom
426 ? string extends TTo
427 ? OptionalToOptions<TRouter, TFrom, TTo>
428 : TTo & CatchAllPaths<TRouter> extends never
429 ? RequiredToOptions<TRouter, TFrom, TTo>
430 : OptionalToOptions<TRouter, TFrom, TTo>
431 : OptionalToOptions<TRouter, TFrom, TTo>
432​
433export type ToSubOptionsProps<
434 TRouter extends AnyRouter = RegisteredRouter,
435 TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
436 TTo extends string | undefined = '.',
437> = MakeToRequired<TRouter, TFrom, TTo> & {
438 hash?: true | Updater<string>
439 state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>
440 from?: FromPathOption<TRouter, TFrom> & {}
441 unsafeRelative?: 'path'
443​
444export type ParamsReducerFn<
445 in out TRouter extends AnyRouter,
446 in out TParamVariant extends ParamVariant,
447 in out TFrom,
448 in out TTo,
449> = (
450 current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,
451) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
452​
453type ParamsReducer<
454 TRouter extends AnyRouter,
455 TParamVariant extends ParamVariant,
456 TFrom,
457 TTo,
458> =
459 | Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
460 | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})
461​
462type ParamVariant = 'PATH' | 'SEARCH'
463​
464export type ResolveRoute<
465 TRouter extends AnyRouter,
466 TFrom,
467 TTo,
468 TPath = ResolveRelativePath<TFrom, TTo>,
469> = TPath extends string
470 ? TFrom extends TPath
471 ? RouteByPath<TRouter['routeTree'], TPath>
472 : RouteByToPath<TRouter, TPath>
473 : never
474​
475type ResolveFromParamType<TParamVariant extends ParamVariant> =
476 TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'
477​
478type ResolveFromAllParams<
479 TRouter extends AnyRouter,
480 TParamVariant extends ParamVariant,
481> = TParamVariant extends 'PATH'
482 ? AllParams<TRouter['routeTree']>
483 : FullSearchSchema<TRouter['routeTree']>
484​
485type ResolveFromParams<
486 TRouter extends AnyRouter,
487 TParamVariant extends ParamVariant,
488 TFrom,
489> = string extends TFrom
490 ? ResolveFromAllParams<TRouter, TParamVariant>
491 : RouteByPath<
492 TRouter['routeTree'],
493 TFrom
494 >['types'][ResolveFromParamType<TParamVariant>]
495​
496type ResolveToParamType<TParamVariant extends ParamVariant> =
497 TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'
498​
499type ResolveAllToParams<
500 TRouter extends AnyRouter,
501 TParamVariant extends ParamVariant,
502> = TParamVariant extends 'PATH'
503 ? AllParams<TRouter['routeTree']>
504 : FullSearchSchemaInput<TRouter['routeTree']>
505​
506export type ResolveToParams<
507 TRouter extends AnyRouter,
508 TParamVariant extends ParamVariant,
509 TFrom,
510 TTo,
511> =
512 ResolveRelativePath<TFrom, TTo> extends infer TPath
513 ? undefined extends TPath
514 ? never
515 : string extends TPath
516 ? ResolveAllToParams<TRouter, TParamVariant>
517 : TPath extends CatchAllPaths<TRouter>
518 ? ResolveAllToParams<TRouter, TParamVariant>
519 : ResolveRoute<
520 TRouter,
521 TFrom,
522 TTo
523 >['types'][ResolveToParamType<TParamVariant>]
524 : never
525​
526type ResolveRelativeToParams<
527 TRouter extends AnyRouter,
528 TParamVariant extends ParamVariant,
529 TFrom,
530 TTo,
531 TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>,
532> = TParamVariant extends 'SEARCH'
533 ? TToParams
534 : string extends TFrom
535 ? TToParams
536 : MakeDifferenceOptional<
537 ResolveFromParams<TRouter, TParamVariant, TFrom>,
538 TToParams
539 >
540​
541export interface MakeOptionalSearchParams<
542 in out TRouter extends AnyRouter,
543 in out TFrom,
544 in out TTo,
545> {
546 search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})
548​
549export interface MakeOptionalPathParams<
550 in out TRouter extends AnyRouter,
551 in out TFrom,
552 in out TTo,
553> {
554 params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})
556​
557type MakeRequiredParamsReducer<
558 TRouter extends AnyRouter,
559 TParamVariant extends ParamVariant,
560 TFrom,
561 TTo,
562> =
563 | (string extends TFrom
564 ? never
565 : ResolveFromParams<
566 TRouter,
567 TParamVariant,
568 TFrom
569 > extends ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
570 ? true
571 : never)
572 | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})
573​
574export interface MakeRequiredPathParams<
575 in out TRouter extends AnyRouter,
576 in out TFrom,
577 in out TTo,
578> {
579 params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}
581​
582export interface MakeRequiredSearchParams<
583 in out TRouter extends AnyRouter,
584 in out TFrom,
585 in out TTo,
586> {
587 search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}
589​
590export type IsRequired<
591 TRouter extends AnyRouter,
592 TParamVariant extends ParamVariant,
593 TFrom,
594 TTo,
595> =
596 ResolveRelativePath<TFrom, TTo> extends infer TPath
597 ? undefined extends TPath
598 ? never
599 : TPath extends CatchAllPaths<TRouter>
600 ? never
601 : IsRequiredParams<
602 ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
603 >
604 : never
605​
606export type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> =
607 IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never
608 ? MakeOptionalSearchParams<TRouter, TFrom, TTo>
609 : MakeRequiredSearchParams<TRouter, TFrom, TTo>
610​
611export type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> =
612 IsRequired<TRouter, 'PATH', TFrom, TTo> extends never
613 ? MakeOptionalPathParams<TRouter, TFrom, TTo>
614 : MakeRequiredPathParams<TRouter, TFrom, TTo>
615​
616export type ToPathOption<
617 TRouter extends AnyRouter = AnyRouter,
618 TFrom extends string = string,
619 TTo extends string | undefined = string,
620> = ConstrainLiteral<
621 TTo,
622 RelativeToPathAutoComplete<
623 TRouter,
624 NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',
625 NoInfer<TTo> & string
626 >
628​
629export type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<
630 TFrom,
631 RoutePaths<TRouter['routeTree']>
633​
634/**
635 * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)
636 */
637export interface ActiveOptions {
638 /**
639 * If true, the link will be active if the current route matches the `to` route path exactly (no children routes)
640 * @default false
641 */
642 exact?: boolean
643 /**
644 * If true, the link will only be active if the current URL hash matches the `hash` prop
645 * @default false
646 */
647 includeHash?: boolean
648 /**
649 * If true, the link will only be active if the current URL search params inclusively match the `search` prop
650 * @default true
651 */
652 includeSearch?: boolean
653 /**
654 * This modifies the `includeSearch` behavior.
655 * If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.
656 * @default false
657 */
658 explicitUndefined?: boolean
660​
661export interface LinkOptionsProps {
662 /**
663 * The standard anchor tag target attribute
664 */
665 target?: HTMLAnchorElement['target']
666 /**
667 * Configurable options to determine if the link should be considered active or not
668 * @default {exact:true,includeHash:true}
669 */
670 activeOptions?: ActiveOptions
671 /**
672 * The preloading strategy for this link
673 * - `false` - No preloading
674 * - `'intent'` - Preload the linked route when the user focuses, hovers over, or touches the link
675 * - `'viewport'` - Preload the linked route when it enters the viewport
676 * - `'render'` - Preload the linked route as soon as it renders
677 */
678 preload?: false | 'intent' | 'viewport' | 'render'
679 /**
680 * Delays focus, hover, and viewport preloading by this many milliseconds.
681 * Touch intent preloads immediately. If focus or hover ends, or the link
682 * leaves the viewport before this delay, the preload will be cancelled.
683 */
684 preloadDelay?: number
685 /**
686 * Control whether the link should be disabled or not
687 * If set to `true`, the link will be rendered without an `href` attribute
688 * @default false
689 */
690 disabled?: boolean
691 /**
692 * When the preload strategy is set to `intent`, this controls the proximity of the link to the cursor before it is preloaded.
693 * If the user exits this proximity before this delay, the preload will be cancelled.
694 */
695 preloadIntentProximity?: number
697​
698export type LinkOptions<
699 TRouter extends AnyRouter = RegisteredRouter,
700 TFrom extends string = string,
701 TTo extends string | undefined = '.',
702 TMaskFrom extends string = TFrom,
703 TMaskTo extends string = '.',
704> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps
705​
706export const preloadWarning = 'Error preloading route! ☝️'