import { ActionFunction, LoaderFunction, ShouldRevalidateFunction, } from 'react-router-dom'; import { ChildRouteMap } from './routeFn'; import { ExtractParamsParserReturnTypes, InferParamGroups, OptionalParamNames, RequiredParamNames, RouteElement, RouteOptions, SerializedParams, TemplateParserMap, } from './types'; export type RouteNodeRouteObject = { /** * The component for this route */ element: RouteElement; /** * The element for the index route */ index?: RouteNodeRouteObject; /** * The element for the index route */ layout?: RouteNodeRouteObject; /** * See https://reactrouter.com/en/main/route/loader */ loader?: LoaderFunction; /** * See https://reactrouter.com/en/main/route/route#casesensitive */ caseSensitive?: boolean; /** * See https://reactrouter.com/en/main/route/action */ action?: ActionFunction; /** * See https://reactrouter.com/en/main/route/error-element */ errorElement?: JSX.Element; /** * See https://reactrouter.com/en/main/route/should-revalidate */ shouldRevalidate?: ShouldRevalidateFunction; }; export type RouteNodeBase< T extends string, CRM extends ChildRouteMap, RO extends RouteOptions > = { /** * The Route template including the query template */ templateWithQuery: T; /** * The Route template for react-router-dom */ template: string; /** * The full Route template including parent route */ fullTemplate: string; /** * The RouteOptions for this route with inherited parent options */ options: RO extends undefined ? undefined : Required; /** * The child routes of this route */ children: CRM; layout: RouteNodeRouteObject | undefined; index: RouteNodeRouteObject | undefined; } & RouteNodeRouteObject; /** * If the given RouteNode has Parameters * @internal */ export function isRouteNodeWithParams( node: any ): node is RouteNodeWithParams { return node['paramsMap'] !== undefined; } export type RouteNodeWithParams< T extends string, TPM extends TemplateParserMap, CRM extends ChildRouteMap, RO extends RouteOptions > = RouteNodeBase & { paramsMap: TPM; parseParams: >( params: SerializedParams> & Partial>> ) => ExtractParamsParserReturnTypes> & Partial>>; } & (>( params: ExtractParamsParserReturnTypes> & Partial>> ) => { $: string; } & { [K in keyof CRM]: CRM[K]; }); export type RouteNodeWithoutParams< T extends string, CRM extends ChildRouteMap, RO extends RouteOptions > = RouteNodeBase & (() => { $: string; } & { [K in keyof CRM]: CRM[K]; }); export type RouteNode< T extends string, TPM extends TemplateParserMap, CRM extends ChildRouteMap, RO extends RouteOptions > = keyof TemplateParserMap extends never ? RouteNodeWithoutParams : RouteNodeWithParams; export type AnyRouteNode = | RouteNodeWithoutParams | RouteNodeWithParams; export type AnyOptionsRouteNode = | RouteNodeWithoutParams | RouteNodeWithParams;