/** * These are vendored from react-router v3 * * Once we've fully migrated to react-router 6 we can drop these types */ import type { Href, Location, LocationDescriptor, LocationState, Path, Pathname, Query, } from 'history'; interface Params { [key: string]: string; } type RoutePattern = string; export type RouteComponent = React.ComponentClass | React.FunctionComponent; interface RouteComponents { [name: string]: RouteComponent; } interface RouterState { components: RouteComponent[]; location: Location; params: Params; routes: PlainRoute[]; } interface RedirectFunction { (location: LocationDescriptor): void; (state: LocationState, pathname: Pathname | Path, query?: Query): void; } type AnyFunction = (...args: any[]) => any; type EnterHook = ( nextState: RouterState, replace: RedirectFunction, callback?: AnyFunction ) => any; type LeaveHook = (prevState: RouterState) => any; type ChangeHook = ( prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback?: AnyFunction ) => any; type RouteHook = (nextLocation?: Location) => any; type ComponentCallback = (err: any, component: RouteComponent) => any; type ComponentsCallback = (err: any, components: RouteComponents) => any; export interface IndexRouteProps { component?: RouteComponent | undefined; components?: RouteComponents | undefined; getComponent?(nextState: RouterState, callback: ComponentCallback): void; getComponents?(nextState: RouterState, callback: ComponentsCallback): void; onChange?: ChangeHook | undefined; onEnter?: EnterHook | undefined; onLeave?: LeaveHook | undefined; props?: Props | undefined; } export interface RouteProps extends IndexRouteProps { children?: React.ReactNode; path?: RoutePattern | undefined; } type RouteCallback = (err: any, route: PlainRoute) => void; type RoutesCallback = (err: any, routesArray: PlainRoute[]) => void; export interface PlainRoute extends RouteProps { childRoutes?: PlainRoute[] | undefined; getChildRoutes?(partialNextState: LocationState, callback: RoutesCallback): void; getIndexRoute?(partialNextState: LocationState, callback: RouteCallback): void; indexRoute?: PlainRoute | undefined; } export interface RouteComponentProps { location: Location; params: P & R; route: PlainRoute; routeParams: R; router: InjectedRouter; routes: PlainRoute[]; } type LocationFunction = (location: LocationDescriptor) => void; type GoFunction = (n: number) => void; type NavigateFunction = () => void; type ActiveFunction = (location: LocationDescriptor, indexOnly?: boolean) => boolean; type LeaveHookFunction = (route: any, callback: RouteHook) => () => void; type CreatePartFunction = (pathOrLoc: LocationDescriptor, query?: any) => Part; export interface InjectedRouter

, Q = any> { createHref: CreatePartFunction; createPath: CreatePartFunction; go: GoFunction; goBack: NavigateFunction; goForward: NavigateFunction; isActive: ActiveFunction; location: Location; params: P; push: LocationFunction; replace: LocationFunction; routes: PlainRoute[]; setRouteLeaveHook: LeaveHookFunction; } export interface WithRouterProps

, Q = any> { location: Location; params: P; router: InjectedRouter; routes: PlainRoute[]; } export interface RouteContextInterface

, Q = any> { location: Location; params: P; router: InjectedRouter; routes: PlainRoute[]; } export type Route = React.ComponentClass; export interface IndexRedirectProps { to: RoutePattern; query?: Query | undefined; } export interface RedirectProps extends IndexRedirectProps { from: RoutePattern; }