import { HistoryState, ParsedHistoryState } from '@tanstack/history'; import { AllParams, CatchAllPaths, CurrentPath, FullSearchSchema, FullSearchSchemaInput, ParentPath, RouteByPath, RouteByToPath, RoutePaths, RouteToPath, ToPath } from './routeInfo.cjs'; import { AnyRouter, RegisteredRouter, ViewTransitionOptions } from './router.cjs'; import { ConstrainLiteral, Expand, MakeDifferenceOptional, NoInfer, NonNullableUpdater, PickRequired, Updater, WithoutEmpty } from './utils.cjs'; import { ParsedLocation } from './location.cjs'; export type IsRequiredParams = Record extends TParams ? never : true; export type ParsePathParams = T & `${string}$${string}` extends never ? TAcc : T extends `${string}$${infer TPossiblyParam}` ? TPossiblyParam extends '' ? TAcc : TPossiblyParam & `${string}/${string}` extends never ? TPossiblyParam | TAcc : TPossiblyParam extends `${infer TParam}/${infer TRest}` ? ParsePathParams : never : TAcc; export type AddTrailingSlash = T extends `${string}/` ? T : `${T & string}/`; export type RemoveTrailingSlashes = T & `${string}/` extends never ? T : T extends `${infer R}/` ? R : T; export type AddLeadingSlash = T & `/${string}` extends never ? `/${T & string}` : T; export type RemoveLeadingSlashes = T & `/${string}` extends never ? T : T extends `/${infer R}` ? R : T; type JoinPath = TRight extends '' ? TLeft : TLeft extends '' ? TRight : `${RemoveTrailingSlashes}/${RemoveLeadingSlashes}`; type RemoveLastSegment = T extends `${infer TSegment}/${infer TRest}` ? TRest & `${string}/${string}` extends never ? TRest extends '' ? TAcc : `${TAcc}${TSegment}` : RemoveLastSegment : TAcc; export type ResolveCurrentPath = TTo extends '.' ? TFrom : TTo extends './' ? AddTrailingSlash : TTo & `./${string}` extends never ? never : TTo extends `./${infer TRest}` ? AddLeadingSlash> : never; export type ResolveParentPath = TTo extends '../' | '..' ? TFrom extends '' | '/' ? never : AddLeadingSlash> : TTo & `../${string}` extends never ? AddLeadingSlash> : TFrom extends '' | '/' ? never : TTo extends `../${infer ToRest}` ? ResolveParentPath, ToRest> : AddLeadingSlash>; export type ResolveRelativePath = string extends TFrom ? TTo : string extends TTo ? TFrom : undefined extends TTo ? TFrom : TTo extends string ? TFrom extends string ? TTo extends `/${string}` ? TTo : TTo extends `..${string}` ? ResolveParentPath : TTo extends `.${string}` ? ResolveCurrentPath : AddLeadingSlash> : never : never; export type FindDescendantToPaths = `${TPrefix}/${string}` & RouteToPath; export type InferDescendantToPaths> = TPaths extends `${TPrefix}/` ? never : TPaths extends `${TPrefix}/${infer TRest}` ? TRest : never; export type RelativeToPath = (TResolvedPath & RouteToPath extends never ? never : ToPath) | `${RemoveTrailingSlashes}/${InferDescendantToPaths>}`; export type RelativeToParentPath> = RelativeToPath | (TTo extends `${string}..` | `${string}../` ? TResolvedPath extends '/' | '' ? never : FindDescendantToPaths> extends never ? never : `${RemoveTrailingSlashes}/${ParentPath}` : never); export type RelativeToCurrentPath> = RelativeToPath | CurrentPath; export type AbsoluteToPath = (string extends TFrom ? CurrentPath : TFrom extends `/` ? never : CurrentPath) | (string extends TFrom ? ParentPath : TFrom extends `/` ? never : ParentPath) | RouteToPath | (TFrom extends '/' ? never : string extends TFrom ? never : InferDescendantToPaths>); export type RelativeToPathAutoComplete = string extends TTo ? string : string extends TFrom ? AbsoluteToPath : TTo & `..${string}` extends never ? TTo & `.${string}` extends never ? AbsoluteToPath : RelativeToCurrentPath : RelativeToParentPath; export type NavigateOptions = ToOptions & NavigateOptionProps; /** * The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router. * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType) */ export interface NavigateOptionProps { /** * If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`. * If set to `false`, the router will not scroll the element with an id matching the hash into view. * If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options. * @default true * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview) * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) */ hashScrollIntoView?: boolean | ScrollIntoViewOptions; /** * `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one. * @default false * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace) */ replace?: boolean; /** * Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history. * If `false`, the scroll position will not be reset to 0,0 after the location is committed to history. * @default true * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll) */ resetScroll?: boolean; /** @deprecated All navigations now use startTransition under the hood */ startTransition?: boolean; /** * If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call. * If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})` * where `types` will be the strings array passed with `ViewTransitionOptions["types"]`. * If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed. * * If the browser does not support this api, this option will be ignored. * @default false * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition) * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) * @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types) */ viewTransition?: boolean | ViewTransitionOptions; /** * If `true`, navigation will ignore any blockers that might prevent it. * @default false * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker) */ ignoreBlocker?: boolean; /** * If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation. * @default false * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument) */ reloadDocument?: boolean; /** * This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target. * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href) */ href?: string; } export type ToOptions = ToSubOptions & MaskOptions; export interface MaskOptions { _fromLocation?: ParsedLocation; mask?: ToMaskOptions; } export type ToMaskOptions = ToSubOptions & { unmaskOnReload?: boolean; }; export type ToSubOptions = ToSubOptionsProps & SearchParamOptions & PathParamOptions; export interface RequiredToOptions { to: ToPathOption & {}; } export interface OptionalToOptions { to?: ToPathOption & {}; } export type MakeToRequired = string extends TFrom ? string extends TTo ? OptionalToOptions : TTo & CatchAllPaths extends never ? RequiredToOptions : OptionalToOptions : OptionalToOptions; export type ToSubOptionsProps | string = string, TTo extends string | undefined = '.'> = MakeToRequired & { hash?: true | Updater; state?: true | NonNullableUpdater; from?: FromPathOption & {}; }; export type ParamsReducerFn = (current: Expand>) => Expand>; type ParamsReducer = Expand> | (ParamsReducerFn & {}); type ParamVariant = 'PATH' | 'SEARCH'; export type ResolveRoute> = TPath extends string ? TFrom extends TPath ? RouteByPath : RouteByToPath : never; type ResolveFromParamType = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'; type ResolveFromAllParams = TParamVariant extends 'PATH' ? AllParams : FullSearchSchema; type ResolveFromParams = string extends TFrom ? ResolveFromAllParams : RouteByPath['types'][ResolveFromParamType]; type ResolveToParamType = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'; type ResolveAllToParams = TParamVariant extends 'PATH' ? AllParams : FullSearchSchemaInput; export type ResolveToParams = ResolveRelativePath extends infer TPath ? undefined extends TPath ? never : string extends TPath ? ResolveAllToParams : TPath extends CatchAllPaths ? ResolveAllToParams : ResolveRoute['types'][ResolveToParamType] : never; type ResolveRelativeToParams> = TParamVariant extends 'SEARCH' ? TToParams : string extends TFrom ? TToParams : MakeDifferenceOptional, TToParams>; export interface MakeOptionalSearchParams { search?: true | (ParamsReducer & {}); } export interface MakeOptionalPathParams { params?: true | (ParamsReducer & {}); } type MakeRequiredParamsReducer = (string extends TFrom ? never : ResolveFromParams extends WithoutEmpty>> ? true : never) | (ParamsReducer & {}); export interface MakeRequiredPathParams { params: MakeRequiredParamsReducer & {}; } export interface MakeRequiredSearchParams { search: MakeRequiredParamsReducer & {}; } export type IsRequired = ResolveRelativePath extends infer TPath ? undefined extends TPath ? never : TPath extends CatchAllPaths ? never : IsRequiredParams> : never; export type SearchParamOptions = IsRequired extends never ? MakeOptionalSearchParams : MakeRequiredSearchParams; export type PathParamOptions = IsRequired extends never ? MakeOptionalPathParams : MakeRequiredPathParams; export type ToPathOption = ConstrainLiteral extends string ? NoInfer : '', NoInfer & string>>; export type FromPathOption = ConstrainLiteral>; /** * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options) */ export interface ActiveOptions { /** * If true, the link will be active if the current route matches the `to` route path exactly (no children routes) * @default false */ exact?: boolean; /** * If true, the link will only be active if the current URL hash matches the `hash` prop * @default false */ includeHash?: boolean; /** * If true, the link will only be active if the current URL search params inclusively match the `search` prop * @default true */ includeSearch?: boolean; /** * This modifies the `includeSearch` behavior. * 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. * @default false */ explicitUndefined?: boolean; } export interface LinkOptionsProps { /** * The standard anchor tag target attribute */ target?: HTMLAnchorElement['target']; /** * Configurable options to determine if the link should be considered active or not * @default {exact:true,includeHash:true} */ activeOptions?: ActiveOptions; /** * The preloading strategy for this link * - `false` - No preloading * - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there. * - `'viewport'` - Preload the linked route when it enters the viewport */ preload?: false | 'intent' | 'viewport' | 'render'; /** * When a preload strategy is set, this delays the preload by this many milliseconds. * If the user exits the link before this delay, the preload will be cancelled. */ preloadDelay?: number; /** * Control whether the link should be disabled or not * If set to `true`, the link will be rendered without an `href` attribute * @default false */ disabled?: boolean; } export type LinkOptions = NavigateOptions & LinkOptionsProps; export type LinkCurrentTargetElement = { preloadTimeout?: null | ReturnType; }; export declare const preloadWarning = "Error preloading route! \u261D\uFE0F"; export {};