// Type definitions for React Router 5.1 // Project: https://github.com/ReactTraining/react-router // Definitions by: Sergey Buturlakin // Yuichi Murata // Václav Ostrožlík // Nathan Brown // Alex Wendland // Kostya Esmukov // John Reilly // Karol Janyst // Dovydas Navickas // Huy Nguyen // Jérémy Fauvel // Daniel Roth // Egor Shulga // Rahul Raina // Duong Tran // Ben Smith // Wesley Tsai // Sebastian Silbermann // Nicholas Hehr // Pawel Fajfer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as React from 'react'; import * as H from 'history'; // This is the type of the context object that will be passed down to all children of // a `Router` component: export interface RouterChildContext { router: { history: H.History; route: { location: H.Location; match: match; }; }; } export interface MemoryRouterProps { initialEntries?: H.LocationDescriptor[]; initialIndex?: number; getUserConfirmation?: (message: string, callback: (ok: boolean) => void) => void; keyLength?: number; } export class MemoryRouter extends React.Component {} export interface PromptProps { message: string | ((location: H.Location, action: H.Action) => string | boolean); when?: boolean; } export class Prompt extends React.Component {} export interface RedirectProps { to: H.LocationDescriptor; push?: boolean; from?: string; path?: string; exact?: boolean; strict?: boolean; } export class Redirect extends React.Component {} export interface StaticContext { statusCode?: number; } export interface RouteComponentProps< Params extends { [K in keyof Params]?: string } = {}, C extends StaticContext = StaticContext, S = H.LocationState > { history: H.History; location: H.Location; match: match; staticContext?: C; } export interface RouteChildrenProps { history: H.History; location: H.Location; match: match | null; } export interface RouteProps { location?: H.Location; component?: React.ComponentType> | React.ComponentType; render?: (props: RouteComponentProps) => React.ReactNode; children?: ((props: RouteChildrenProps) => React.ReactNode) | React.ReactNode; path?: string | string[]; exact?: boolean; sensitive?: boolean; strict?: boolean; } export class Route extends React.Component {} export interface RouterProps { history: H.History; } export class Router extends React.Component {} export interface StaticRouterContext extends StaticContext { url?: string; action?: 'PUSH' | 'REPLACE'; location?: object; } export interface StaticRouterProps { basename?: string; location?: string | object; context?: StaticRouterContext; } export class StaticRouter extends React.Component {} export interface SwitchProps { children?: React.ReactNode; location?: H.Location; } export class Switch extends React.Component {} export interface match { params: Params; isExact: boolean; path: string; url: string; } // Omit taken from https://github.com/Microsoft/TypeScript/issues/28339#issuecomment-467220238 export type Omit = T extends any ? Pick> : never; export function matchPath( pathname: string, props: string | string[] | RouteProps, parent?: match | null, ): match | null; export function generatePath( pattern: string, params?: { [paramName: string]: string | number | boolean | undefined }, ): string; export type WithRouterProps> = C extends React.ComponentClass ? { wrappedComponentRef?: React.Ref> } : {}; export interface WithRouterStatics> { WrappedComponent: C; } // There is a known issue in TypeScript, which doesn't allow decorators to change the signature of the classes // they are decorating. Due to this, if you are using @withRouter decorator in your code, // you will see a bunch of errors from TypeScript. The current workaround is to use withRouter() as a function call // on a separate line instead of as a decorator. export function withRouter

, C extends React.ComponentType

>( component: C & React.ComponentType

, ): React.ComponentClass> & WithRouterProps> & WithRouterStatics; export const __RouterContext: React.Context; export function useHistory(): H.History; export function useLocation(): H.Location; export function useParams(): Params; export function useRouteMatch(): match; export function useRouteMatch( path: string | string[] | RouteProps, ): match | null;