import { Component } from 'vue'; import { Param } from './paramTypes'; import { PrefetchConfig } from './prefetch'; import { RouteMeta } from './register'; import { Route } from './route'; import { ResolvedRoute, WithData } from './resolved'; import { ComponentProps } from '../services/component'; import { PropsCallbackContext } from './props'; import { AnyFunction, Identity, MaybePromise } from './utilities'; import { ToMeta } from './meta'; import { ToName } from './name'; import { UrlPart, UrlQueryPart } from '../services/withParams'; import { RouteContext } from './routeContext'; import { RouterViewProps } from '../components/routerView'; import { ToUrl } from './url'; import { CombineUrl } from '../services/combineUrl'; import { RouteView } from './routeViews'; export type WithHost = { /** * Host part of URL. */ host: THost; }; export type WithoutHost = { host?: never; }; export type WithParent = { parent: TParent; }; export declare function isWithParent>(options: T): options is T & WithParent; export type WithoutParent = { parent?: never; }; /** * This type is used to strip the component and components properties from the options object * when creating a Route to simplify and minimize the output type. */ type WithoutComponents = { component: never; components: never; }; export declare function isWithComponent>(options: T): options is T & { component: Component; }; export declare function isWithComponents>(options: T): options is T & { components: Record; }; export type CreateRouteOptions = { /** * Name for route, used to create route keys and in navigation. */ name?: TName; /** * Path part of URL. */ path?: string | UrlPart | undefined; /** * Query (aka search) part of URL. */ query?: string | UrlQueryPart | undefined; /** * Hash part of URL. */ hash?: string | UrlPart | undefined; /** * Represents additional metadata associated with a route, customizable via declaration merging. */ meta?: TMeta; /** * Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch. */ prefetch?: PrefetchConfig; /** * Type params for additional data intended to be stored in history state, all keys will be optional unless a default is provided. */ state?: Record; /** * An optional parent route to nest this route under. */ parent?: Route; /** * An optional component to render when this route is matched. * * @default RouterView * @deprecated Use the chainable `addView` method on the route instead: `createRoute({ ... }).addView(component, { props })`. */ component?: Component; /** * An object of named components to render using named views * * @deprecated Use the chainable `addView` method on the route instead: `createRoute({ ... }).addView(component, { name, props })`. */ components?: Record; /** * Related routes and rejections for the route. The context is exposed to the hooks and props callback functions for this route. */ context?: RouteContext[]; /** * When true, the route will be hoisted to the top of the route tree. The route will continue to inherit meta, state, hooks, matches, and context from it's parent, but not the "url" properties. */ hoist?: boolean; }; export type PropsGetter = (route: ResolvedRoute> & WithData>, context: PropsCallbackContext, TOptions>) => MaybePromise>; export type RouterViewPropsGetter = (route: ResolvedRoute> & WithData>, context: PropsCallbackContext, TOptions>) => MaybePromise>; export type ComponentPropsAreOptional = Partial> extends ComponentProps ? true : false; type RoutePropsRecord = Record> = { [K in keyof TComponents as ComponentPropsAreOptional extends true ? K : never]?: PropsGetter; } & { [K in keyof TComponents as ComponentPropsAreOptional extends false ? K : never]: PropsGetter; }; export type CreateRouteProps = TOptions['component'] extends Component ? PropsGetter : TOptions['components'] extends Record ? RoutePropsRecord : RouterViewPropsGetter; type ToMatch = Omit & { id: string; name: ToName; /** * Represents additional metadata associated with a route. Always present, defaults to empty object. */ meta: ToMeta; /** * The views this route renders, keyed by view name. */ views: PropsToViews; /** * The loaders this route runs, keyed by loader name. Always empty here — loaders are only added via * the route's `addLoader`. */ loaders: {}; }; /** * The matches for a route, from greatest ancestor to the route itself. Each carries its own views, so * there is no second tuple to keep aligned with this one. */ type ToMatches = TOptions extends { parent: infer TParent extends Route; } ? [...TParent['matches'], ToMatch] : [ToMatch]; /** * Builds a views record from the props argument, which is either a single getter for the unnamed view or * a record of getters keyed by view name. */ type PropsToViews = [TProps] extends [AnyFunction] ? { default: RouteView>; } : [TProps] extends [Record] ? { [K in keyof TProps]: RouteView>; } : {}; /** * The url a route resolves to, combined with its parent's unless the route is hoisted. */ export type ToRouteUrl = TOptions extends { parent: infer TParent extends Route; } ? TOptions['hoist'] extends true ? ToUrl : CombineUrl> : ToUrl>; /** * The matches for a route, with the props argument resolved to the views of its own match. */ export type ToRouteMatches = ToMatches extends TProps ? undefined : TProps>; export type ToRoute | undefined = undefined> = CreateRouteOptions extends TOptions ? Route : Route, ToRouteMatches>; export declare function combineRoutes(parent: Route, child: Route): Route; export {};