import { LazyRoute } from './fileRoute.js'; import { NotFoundError } from './not-found.js'; import { RedirectFnRoute } from './redirect.js'; import { NavigateOptions, ParsePathParams } from './link.js'; import { ParsedLocation } from './location.js'; import { AnyRouteMatch, MakePreValidationErrorHandlingRouteMatchUnion, MakeRouteMatchFromRoute, MakeRouteMatchUnion, RouteMatch } from './Matches.js'; import { RootRouteId } from './root.js'; import { ParseRoute, RouteById, RouteIds, RoutePaths } from './routeInfo.js'; import { AnyRouter, Register, RegisteredRouter, SSROption } from './router.js'; import { BuildLocationFn, NavigateFn } from './RouterProvider.js'; import { Assign, Awaitable, Constrain, Expand, IntersectAssign, LooseAsyncReturnType, LooseReturnType, NoInfer } from './utils.js'; import { AnySchema, AnyStandardSchemaValidator, AnyValidator, AnyValidatorAdapter, AnyValidatorObj, DefaultValidator, ResolveSearchValidatorInput, ResolveValidatorOutput, StandardSchemaValidator, ValidatorAdapter, ValidatorFn, ValidatorObj } from './validators.js'; import { ValidateSerializableLifecycleResult } from './ssr/serializer/transformer.js'; export type AnyPathParams = {}; export type SearchSchemaInput = { __TSearchSchemaInput__: 'TSearchSchemaInput'; }; export type AnyContext = {}; export interface RouteContext { } export type PreloadableObj = { preload?: () => Promise; }; export type RoutePathOptions = { path: TPath; } | { id: TCustomId; }; export interface StaticDataRouteOption { } export type RoutePathOptionsIntersection = { path: TPath; id: TCustomId; }; export type SearchFilter = (prev: TInput) => TResult; export type SearchMiddlewareContext = { search: TSearchSchema; next: (newSearch: TSearchSchema) => TSearchSchema; }; export type SearchMiddleware = (ctx: SearchMiddlewareContext) => TSearchSchema; export type ResolveId = TParentRoute extends { id: infer TParentId extends string; } ? RoutePrefix : RootRouteId; export type InferFullSearchSchema = TRoute extends { types: { fullSearchSchema: infer TFullSearchSchema; }; } ? TFullSearchSchema : {}; export type InferFullSearchSchemaInput = TRoute extends { types: { fullSearchSchemaInput: infer TFullSearchSchemaInput; }; } ? TFullSearchSchemaInput : {}; export type InferAllParams = TRoute extends { types: { allParams: infer TAllParams; }; } ? TAllParams : {}; export type InferAllContext = unknown extends TRoute ? TRoute : TRoute extends { types: { allContext: infer TAllContext; }; } ? TAllContext : {}; export type ResolveSearchSchemaFnInput = TSearchValidator extends (input: infer TSearchSchemaInput) => any ? TSearchSchemaInput extends SearchSchemaInput ? Omit : ResolveSearchSchemaFn : AnySchema; export type ResolveSearchSchemaInput = TSearchValidator extends AnyStandardSchemaValidator ? NonNullable['input'] : TSearchValidator extends AnyValidatorAdapter ? TSearchValidator['types']['input'] : TSearchValidator extends AnyValidatorObj ? ResolveSearchSchemaFnInput : ResolveSearchSchemaFnInput; export type ResolveSearchSchemaFn = TSearchValidator extends (...args: any) => infer TSearchSchema ? TSearchSchema : AnySchema; export type ResolveSearchSchema = unknown extends TSearchValidator ? TSearchValidator : TSearchValidator extends AnyStandardSchemaValidator ? NonNullable['output'] : TSearchValidator extends AnyValidatorAdapter ? TSearchValidator['types']['output'] : TSearchValidator extends AnyValidatorObj ? ResolveSearchSchemaFn : ResolveSearchSchemaFn; export type ResolveRequiredParams = { [K in ParsePathParams['required']]: T; }; export type ResolveOptionalParams = { [K in ParsePathParams['optional']]?: T | undefined; }; export type ResolveParams = ResolveRequiredParams & ResolveOptionalParams; export type ParseParamsFn = (rawParams: Expand>) => TParams | false; type ValidateParsedParams = [TParams] extends [ ResolveParams ] ? unknown : never; export type StringifyParamsFn = (params: TParams) => ResolveParams; export type ParamsOptions = { params?: { parse?: ParseParamsFn & ValidateParsedParams; stringify?: StringifyParamsFn; }; /** @deprecated Use params.parse instead */ parseParams?: ParseParamsFn & ValidateParsedParams; /** @deprecated Use params.stringify instead */ stringifyParams?: StringifyParamsFn; }; interface RequiredStaticDataRouteOption { staticData: StaticDataRouteOption; } interface OptionalStaticDataRouteOption { staticData?: StaticDataRouteOption; } export type UpdatableStaticRouteOption = {} extends StaticDataRouteOption ? OptionalStaticDataRouteOption : RequiredStaticDataRouteOption; export type MetaDescriptor = { charSet: 'utf-8'; } | { title: string; } | { name: string; content: string; } | { property: string; content: string; } | { httpEquiv: string; content: string; } | { 'script:ld+json': LdJsonObject; } | { tagName: 'meta' | 'link'; [name: string]: string; } | Record; type LdJsonObject = { [Key in string]: LdJsonValue; } & { [Key in string]?: LdJsonValue | undefined; }; type LdJsonArray = Array | ReadonlyArray; type LdJsonPrimitive = string | number | boolean | null; type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray; export type RouteLinkEntry = {}; export type SearchValidator = ValidatorObj | ValidatorFn | ValidatorAdapter | StandardSchemaValidator | undefined; export type AnySearchValidator = SearchValidator; export type DefaultSearchValidator = SearchValidator, AnySchema>; export type RoutePrefix = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight}/${TrimPath}`>}` : never; export type TrimPath = '' extends T ? '' : TrimPathRight>; export type TrimPathLeft = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft : T extends `/${infer U}` ? TrimPathLeft : T; export type TrimPathRight = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight : T; export type ContextReturnType = unknown extends TContextFn ? TContextFn : LooseReturnType extends never ? AnyContext : LooseReturnType; export type ContextAsyncReturnType = unknown extends TContextFn ? TContextFn : LooseAsyncReturnType extends never ? AnyContext : LooseAsyncReturnType; export type ResolveRouteContext = Assign, ContextAsyncReturnType>; export type ResolveRouteLoaderFn = TLoaderFn extends { handler: infer THandler; } ? THandler : TLoaderFn; export type RouteLoaderObject = { handler: RouteLoaderFn; staleReloadMode?: LoaderStaleReloadMode; }; export type ResolveLoaderData = unknown extends TLoaderFn ? TLoaderFn : LooseAsyncReturnType> extends never ? undefined : LooseAsyncReturnType>; export type ResolveFullSearchSchema = unknown extends TParentRoute ? ResolveValidatorOutput : IntersectAssign, ResolveValidatorOutput>; export type ResolveFullSearchSchemaInput = IntersectAssign, ResolveSearchValidatorInput>; export type ResolveAllParamsFromParent = Assign, TParams>; export type RouteContextParameter = unknown extends TParentRoute ? TRouterContext : Assign>; export type BeforeLoadContextParameter = Assign, ContextReturnType>; export type ResolveAllContext = Assign, ContextAsyncReturnType>; export interface FullSearchSchemaOption { search: Expand>; } export interface RemountDepsOptions { routeId: TRouteId; search: TFullSearchSchema; params: TAllParams; loaderDeps: TLoaderDeps; } export type MakeRemountDepsOptionsUnion = ParseRoute extends infer TRoute extends AnyRoute ? TRoute extends any ? RemountDepsOptions : never : never; export interface RouteTypes { parentRoute: TParentRoute; path: TPath; to: TrimPathRight; fullPath: TFullPath; customId: TCustomId; id: TId; searchSchema: ResolveValidatorOutput; searchSchemaInput: ResolveSearchValidatorInput; searchValidator: TSearchValidator; fullSearchSchema: ResolveFullSearchSchema; fullSearchSchemaInput: ResolveFullSearchSchemaInput; params: TParams; allParams: ResolveAllParamsFromParent; routerContext: TRouterContext; routeContext: ResolveRouteContext; routeContextFn: TRouteContextFn; beforeLoadFn: TBeforeLoadFn; allContext: ResolveAllContext; children: TChildren; loaderData: ResolveLoaderData; loaderDeps: TLoaderDeps; fileRouteTypes: TFileRouteTypes; ssr: ResolveSSR; allSsr: ResolveAllSSR; } export type ResolveSSR = TSSR extends (...args: ReadonlyArray) => any ? LooseReturnType : TSSR; export type ResolveAllSSR = unknown extends TParentRoute ? ResolveSSR : unknown extends TSSR ? TParentRoute['types']['allSsr'] : ResolveSSR; export type ResolveFullPath> = TPrefixed extends RootRouteId ? '/' : TPrefixed; export interface RouteExtensions { id: TId; fullPath: TFullPath; } export type RouteLazyFn = (lazyFn: () => Promise>) => TRoute; export type RouteAddChildrenFn, in out TLoaderFn, in out TFileRouteTypes, in out TSSR, in out TServerMiddlewares, in out THandlers> = (children: Constrain | Record>) => Route; export type RouteAddFileChildrenFn, in out TLoaderFn, in out TFileRouteTypes, in out TSSR, in out TServerMiddlewares, in out THandlers> = (children: TNewChildren) => Route; export type RouteAddFileTypesFn, TLoaderFn, TChildren, TSSR, TServerMiddlewares, THandlers> = () => Route; export interface Route, in out TLoaderFn, in out TChildren, in out TFileRouteTypes, in out TSSR, in out TServerMiddlewares, in out THandlers> extends RouteExtensions { path: TPath; parentRoute: TParentRoute; children?: TChildren; types: RouteTypes; options: RouteOptions; isRoot: TParentRoute extends AnyRoute ? true : false; lazyFn?: () => Promise>>; rank: number; to: TrimPathRight; init: (opts: { originalIndex: number; }) => void; update: (options: UpdatableRouteOptions) => this; lazy: RouteLazyFn>; addChildren: RouteAddChildrenFn; _addFileChildren: RouteAddFileChildrenFn; _addFileTypes: RouteAddFileTypesFn; /** * Create a redirect with `from` automatically set to this route's path. * Enables relative redirects like `Route.redirect({ to: './overview' })`. * @param opts Redirect options (same as `redirect()` but without `from`) * @returns A redirect Response that can be thrown from loaders/beforeLoad * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction */ redirect: RedirectFnRoute; } export type AnyRoute = Route; export type AnyRouteWithContext = AnyRoute & { types: { allContext: TContext; }; }; export type RouteOptions = {}, TLoaderFn = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TSSR = unknown, TServerMiddlewares = unknown, THandlers = undefined> = BaseRouteOptions & UpdatableRouteOptions, NoInfer, NoInfer, NoInfer, NoInfer, NoInfer, NoInfer, NoInfer, NoInfer, NoInfer>; export type RouteContextFn = (ctx: RouteContextOptions) => any; export type FileBaseRouteOptions = {}, TLoaderFn = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TRemountDepsFn = AnyContext, TSSR = unknown, TServerMiddlewares = unknown, THandlers = undefined> = ParamsOptions & FilebaseRouteOptionsInterface; export interface FilebaseRouteOptionsInterface = {}, TLoaderFn = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TRemountDepsFn = AnyContext, TSSR = unknown, TServerMiddlewares = unknown, THandlers = undefined> { validateSearch?: Constrain; shouldReload?: boolean | ((match: LoaderFnContext) => any); context?: Constrain) => any>; ssr?: Constrain) => Awaitable)>; beforeLoad?: Constrain) => ValidateSerializableLifecycleResult>; loaderDeps?: (opts: FullSearchSchemaOption) => TLoaderDeps; remountDeps?: Constrain, Expand>, TLoaderDeps>) => any>; loader?: Constrain | RouteLoaderObject>; } export type BaseRouteOptions = {}, TLoaderFn = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TSSR = unknown, TServerMiddlewares = unknown, THandlers = undefined> = RoutePathOptions & FileBaseRouteOptions & { getParentRoute: () => TParentRoute; }; export interface ContextOptions { abortController: AbortController; preload: boolean; params: Expand>; location: ParsedLocation; /** * @deprecated Use `throw redirect({ to: '/somewhere' })` instead **/ navigate: NavigateFn; buildLocation: BuildLocationFn; cause: 'preload' | 'enter' | 'stay'; matches: Array; routeId: TRouteId; } export interface RouteContextOptions extends ContextOptions { deps: TLoaderDeps; context: Expand>; } export interface SsrContextOptions { params: { status: 'success'; value: Expand>; } | { status: 'error'; error: unknown; }; search: { status: 'success'; value: Expand>; } | { status: 'error'; error: unknown; }; location: ParsedLocation; matches: Array; } export interface BeforeLoadContextOptions extends ContextOptions, FullSearchSchemaOption { context: Expand>; } type AssetFnContextOptions = { ssr?: { nonce?: string; }; matches: Array, ResolveFullSearchSchema, ResolveLoaderData, ResolveAllContext, TLoaderDeps>>; match: RouteMatch, ResolveFullSearchSchema, ResolveLoaderData, ResolveAllContext, TLoaderDeps>; params: ResolveAllParamsFromParent; loaderData?: ResolveLoaderData; }; export interface DefaultUpdatableRouteOptionsExtensions { component?: unknown; errorComponent?: unknown; notFoundComponent?: unknown; pendingComponent?: unknown; } export interface UpdatableRouteOptionsExtensions extends DefaultUpdatableRouteOptionsExtensions { } export interface UpdatableRouteOptions extends UpdatableStaticRouteOption, UpdatableRouteOptionsExtensions { /** * If true, this route will be matched as case-sensitive * * @default false */ caseSensitive?: boolean; /** * If true, this route will be forcefully wrapped in a suspense boundary */ wrapInSuspense?: boolean; pendingMs?: number; pendingMinMs?: number; staleTime?: number; gcTime?: number; preload?: boolean; preloadStaleTime?: number; preloadGcTime?: number; search?: { middlewares?: Array>>; }; /** @deprecated Use search.middlewares instead */ preSearchFilters?: Array>>; /** @deprecated Use search.middlewares instead */ postSearchFilters?: Array>>; onCatch?: (error: Error) => void; onError?: (err: any) => void; onEnter?: (match: RouteMatch, ResolveFullSearchSchema, ResolveLoaderData, ResolveAllContext, TLoaderDeps>) => void; onStay?: (match: RouteMatch, ResolveFullSearchSchema, ResolveLoaderData, ResolveAllContext, TLoaderDeps>) => void; onLeave?: (match: RouteMatch, ResolveFullSearchSchema, ResolveLoaderData, ResolveAllContext, TLoaderDeps>) => void; headers?: (ctx: AssetFnContextOptions) => Awaitable | undefined>; head?: (ctx: AssetFnContextOptions) => Awaitable<{ links?: AnyRouteMatch['links']; scripts?: AnyRouteMatch['headScripts']; meta?: AnyRouteMatch['meta']; styles?: AnyRouteMatch['styles']; }>; scripts?: (ctx: AssetFnContextOptions) => Awaitable; codeSplitGroupings?: Array>; } export type RouteLoaderFn = (match: LoaderFnContext) => any; export type LoaderStaleReloadMode = 'background' | 'blocking'; export type RouteLoaderEntry = RouteLoaderFn | RouteLoaderObject; export interface LoaderFnContext { abortController: AbortController; preload: boolean; params: Expand>; deps: TLoaderDeps; context: Expand>; location: ParsedLocation; /** * @deprecated Use `throw redirect({ to: '/somewhere' })` instead **/ navigate: (opts: NavigateOptions) => Promise | void; parentMatchPromise: TId extends RootRouteId ? never : Promise>; cause: 'preload' | 'enter' | 'stay'; route: AnyRoute; } export interface DefaultRootRouteOptionsExtensions { shellComponent?: unknown; } export interface RootRouteOptionsExtensions extends DefaultRootRouteOptionsExtensions { } export interface RootRouteOptions = {}, TLoaderFn = undefined, TSSR = unknown, TServerMiddlewares = unknown, THandlers = undefined> extends Omit, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'params'>, RootRouteOptionsExtensions { } export type RouteConstraints = { TParentRoute: AnyRoute; TPath: string; TFullPath: string; TCustomId: string; TId: string; TSearchSchema: AnySchema; TFullSearchSchema: AnySchema; TParams: Record; TAllParams: Record; TParentContext: AnyContext; TRouteContext: RouteContext; TAllContext: AnyContext; TRouterContext: AnyContext; TChildren: unknown; TRouteTree: AnyRoute; }; export type RouteTypesById = RouteById['types']; export type RouteMask = { routeTree: TRouteTree; from: RoutePaths; to?: any; params?: any; search?: any; hash?: any; state?: any; unmaskOnReload?: boolean; }; /** * @deprecated Use `ErrorComponentProps` instead. */ export type ErrorRouteProps = { error: unknown; info?: { componentStack: string; }; reset: () => void; }; export type ErrorComponentProps = { error: TError; info?: { componentStack: string; }; reset: () => void; }; export type NotFoundRouteProps = { data?: unknown; isNotFound: boolean; routeId: RouteIds; }; export declare class BaseRoute, in out TCustomId extends string = string, in out TId extends string = ResolveId, in out TSearchValidator = undefined, in out TParams = ResolveParams, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown, in out TSSR = unknown, in out TServerMiddlewares = unknown, in out THandlers = undefined> { isRoot: TParentRoute extends AnyRoute ? true : false; options: RouteOptions; parentRoute: TParentRoute; private _id; private _path; private _fullPath; private _to; get to(): TrimPathRight; get id(): TId; get path(): TPath; get fullPath(): TFullPath; children?: TChildren; originalIndex?: number; rank: number; lazyFn?: () => Promise>>; constructor(options?: RouteOptions); types: RouteTypes; init: (opts: { originalIndex: number; }) => void; addChildren: RouteAddChildrenFn; _addFileChildren: RouteAddFileChildrenFn; _addFileTypes: RouteAddFileTypesFn; updateLoader: (options: { loader: Constrain>; }) => BaseRoute; update: (options: UpdatableRouteOptions) => this; lazy: RouteLazyFn>; /** * Create a redirect with `from` automatically set to this route's fullPath. * Enables relative redirects like `Route.redirect({ to: './overview' })`. * @param opts Redirect options (same as `redirect()` but without `from`) * @returns A redirect Response that can be thrown from loaders/beforeLoad * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction */ redirect: RedirectFnRoute; } export declare class BaseRouteApi { id: TId; constructor({ id }: { id: TId; }); notFound: (opts?: NotFoundError) => NotFoundError; /** * Create a redirect with `from` automatically set to this route's path. * Enables relative redirects like `routeApi.redirect({ to: './overview' })`. * @param opts Redirect options (same as `redirect()` but without `from`) * @returns A redirect Response that can be thrown from loaders/beforeLoad * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction */ redirect: RedirectFnRoute['fullPath']>; } export interface RootRoute = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown, in out TSSR = unknown, in out TServerMiddlewares = unknown, in out THandlers = undefined> extends Route { } export declare class BaseRootRoute = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown, in out TSSR = unknown, in out TServerMiddlewares = unknown, in out THandlers = undefined> extends BaseRoute { constructor(options?: RootRouteOptions); } export interface RouteLike { id: string; isRoot?: boolean; path?: string; fullPath: string; rank?: number; parentRoute?: RouteLike; children?: Array; options?: { caseSensitive?: boolean; }; } export {};