import { Param } from './paramTypes'; import { PrefetchConfig } from './prefetch'; import { RouteMeta } from './register'; import { LastInArray } from './utilities'; import { CreateRouteOptions } from './createRouteOptions'; import { RouteContext, ToRouteContext } from './routeContext'; import { ToMeta } from './meta'; import { ToState } from './state'; import { Url } from './url'; import { GetRouteTitle } from './routeTitle'; import { Hooks } from '../models/hooks'; import { RouteRedirect } from './redirects'; import { RouteViews } from './routeViews'; import { LoadersDataReturnType, RouteLoaders } from './routeLoaders'; export declare const IS_ROUTE_SYMBOL: unique symbol; export declare function isRoute(value: unknown): value is Route & RouteInternal; export type RouteInternal = { [IS_ROUTE_SYMBOL]: true; depth: number; hooks: Hooks[]; redirect: RouteRedirect; getTitle: GetRouteTitle; }; /** * Represents an immutable array of Route instances. Return value of `createRoute`, expected param for `createRouter`. */ export type Routes = readonly Route[]; /** * The Route properties originally provided to `createRoute`, plus the views that route renders and the * loaders it runs. The deprecated `component`/`components` options are folded into `views` (see * {@link RouteViews}). */ export type CreatedRouteOptions = Omit & { id: string; views: RouteViews; loaders: RouteLoaders; }; /** * The name of the narrowest matched route. */ type RouteNameOf = LastInArray extends { name: infer TName extends string; } ? TName : string; /** * The meta of every matched route, combined. Mirrors `combineMeta`, which is an intersection. */ type RouteMetaOf = CreatedRouteOptions[] extends TMatches ? RouteMeta : TMatches extends [infer THead, ...infer TRest extends CreatedRouteOptions[]] ? ToMeta & RouteMetaOf : {}; /** * The state of every matched route, combined. Mirrors `combineState`, which is an intersection. * A match without state contributes `{}` rather than `ToState`, which widens to * `Record` and would swallow the rest of the intersection. */ type RouteStateOf = CreatedRouteOptions[] extends TMatches ? Record : TMatches extends [infer THead, ...infer TRest extends CreatedRouteOptions[]] ? (THead extends { state: infer TState extends Record; } ? ToState : {}) & RouteStateOf : {}; /** * The loaders of every matched route, combined. A plain intersection: a loader name is unique across a * route and its ancestors, which `addLoader` enforces. */ type RouteLoadersOf = CreatedRouteOptions[] extends TMatches ? RouteLoaders : TMatches extends [infer THead, ...infer TRest extends CreatedRouteOptions[]] ? (THead extends { loaders: infer TLoaders extends RouteLoaders; } ? TLoaders : {}) & RouteLoadersOf : {}; /** * The data every matched route's loaders resolve to, which is what a resolved route exposes as `data`. * Undefined when nothing in the route tree declares a loader. */ export type RouteDataOf = CreatedRouteOptions[] extends TMatches ? Promise | Record> | undefined : LoadersDataReturnType>; /** * The context of every matched route, flattened from greatest ancestor to narrowest matched. */ type RouteContextOf = CreatedRouteOptions[] extends TMatches ? RouteContext[] : TMatches extends [infer THead, ...infer TRest extends CreatedRouteOptions[]] ? [...ToRouteContext, ...RouteContextOf] : []; /** * Represents the structure of a route within the application. Return value of `createRoute` * @template TUrl - The url the route resolves to, combined with any parents. Intersected into the route. * @template TMatches - The options of the route and its ancestors, indexed by depth. Name, meta, state, * and context are all derived from this, including each route's views. */ export type Route = TUrl & { /** * Unique identifier for the route, generated by router. */ id: string; /** * The specific route properties that were matched in the current route, including any ancestors. * Order of routes will be from greatest ancestor to narrowest matched. */ matches: TMatches; /** * Identifier for the route as defined by user. Name must be unique among named routes. Name is used for routing and for matching. */ name: RouteNameOf; /** * Represents additional metadata associated with a route, combined with any parents. */ meta: RouteMetaOf; /** * Represents the schema of the route state, combined with any parents. */ state: RouteStateOf; /** * Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch. */ prefetch?: PrefetchConfig; /** * Related routes and rejections for the route. The context is exposed to the hooks and props callback functions for this route. */ context: RouteContextOf; }; export type GenericRoute = Url & { id: string; name: string; matches: CreatedRouteOptions[]; meta: RouteMeta; state: Record; prefetch?: PrefetchConfig; }; export {};