@types/react-router

  • Version 5.1.20
  • Published
  • 21.7 kB
  • 2 dependencies
  • MIT license

Install

npm i @types/react-router
yarn add @types/react-router
pnpm add @types/react-router

Overview

TypeScript definitions for React Router

Index

Functions

function generatePath

generatePath: <S extends string>(
path: S,
params?: ExtractRouteParams<S>
) => string;

    function matchPath

    matchPath: <Params extends { [K in keyof Params]?: string }>(
    pathname: string,
    props: string | string[] | RouteProps,
    parent?: match<Params> | null
    ) => match<Params> | null;

      function useHistory

      useHistory: <
      HistoryLocationState = H.LocationState
      >() => H.History<HistoryLocationState>;

        function useLocation

        useLocation: <S = H.LocationState>() => H.Location<S>;

          function useParams

          useParams: <Params extends { [K in keyof Params]?: string } = {}>() => Params;

            function useRouteMatch

            useRouteMatch: {
            <Params extends { [K in keyof Params]?: string } = {}>(): match<Params>;
            <Params extends { [K in keyof Params]?: string } = {}>(
            path: string | string[] | RouteProps<string, { [x: string]: string }>
            ): match<Params>;
            };

              function withRouter

              withRouter: <
              P extends RouteComponentProps<any, StaticContext, H.LocationState>,
              C extends React.ComponentType<P>
              >(
              component: C & React.ComponentType<P>
              ) => React.ComponentClass<
              Omit<P, keyof RouteComponentProps<any>> & WithRouterProps<C>
              > &
              WithRouterStatics<C>;

                Classes

                class MemoryRouter

                class MemoryRouter extends React.Component<MemoryRouterProps, any> {}

                  class Prompt

                  class Prompt extends React.Component<PromptProps, any> {}

                    class Redirect

                    class Redirect extends React.Component<RedirectProps, any> {}

                      class Route

                      class Route<T extends {} = {}, Path extends string = string> extends React.Component<
                      RouteProps<Path> & OmitNative<T, keyof RouteProps>,
                      any
                      > {}

                        class Router

                        class Router extends React.Component<RouterProps, any> {}

                          class StaticRouter

                          class StaticRouter extends React.Component<StaticRouterProps, any> {}

                            class Switch

                            class Switch extends React.Component<SwitchProps, any> {}

                              Interfaces

                              interface match

                              interface match<Params extends { [K in keyof Params]?: string } = {}> {}

                                property isExact

                                isExact: boolean;

                                  property params

                                  params: Params;

                                    property path

                                    path: string;

                                      property url

                                      url: string;

                                        interface MemoryRouterProps

                                        interface MemoryRouterProps {}

                                          property children

                                          children?: React.ReactNode;

                                            property getUserConfirmation

                                            getUserConfirmation?:
                                            | ((message: string, callback: (ok: boolean) => void) => void)
                                            | undefined;

                                              property initialEntries

                                              initialEntries?: H.LocationDescriptor[] | undefined;

                                                property initialIndex

                                                initialIndex?: number | undefined;

                                                  property keyLength

                                                  keyLength?: number | undefined;

                                                    interface PromptProps

                                                    interface PromptProps {}

                                                      property message

                                                      message: string | ((location: H.Location, action: H.Action) => string | boolean);

                                                        property when

                                                        when?: boolean | undefined;

                                                          interface RedirectProps

                                                          interface RedirectProps {}

                                                            property exact

                                                            exact?: boolean | undefined;

                                                              property from

                                                              from?: string | undefined;

                                                                property path

                                                                path?: string | undefined;

                                                                  property push

                                                                  push?: boolean | undefined;

                                                                    property strict

                                                                    strict?: boolean | undefined;

                                                                      property to

                                                                      to: H.LocationDescriptor;

                                                                        interface RouteChildrenProps

                                                                        interface RouteChildrenProps<
                                                                        Params extends { [K in keyof Params]?: string } = {},
                                                                        S = H.LocationState
                                                                        > {}

                                                                          property history

                                                                          history: H.History;

                                                                            property location

                                                                            location: H.Location<S>;

                                                                              property match

                                                                              match: match<Params> | null;

                                                                                interface RouteComponentProps

                                                                                interface RouteComponentProps<
                                                                                Params extends { [K in keyof Params]?: string } = {},
                                                                                C extends StaticContext = StaticContext,
                                                                                S = H.LocationState
                                                                                > {}

                                                                                  property history

                                                                                  history: H.History<S>;

                                                                                    property location

                                                                                    location: H.Location<S>;

                                                                                      property match

                                                                                      match: match<Params>;

                                                                                        property staticContext

                                                                                        staticContext?: C | undefined;

                                                                                          interface RouteProps

                                                                                          interface RouteProps<
                                                                                          Path extends string = string,
                                                                                          Params extends { [K: string]: string | undefined } = ExtractRouteParams<
                                                                                          Path,
                                                                                          string
                                                                                          >
                                                                                          > {}

                                                                                            property children

                                                                                            children?:
                                                                                            | ((props: RouteChildrenProps<Params>) => React.ReactNode)
                                                                                            | React.ReactNode
                                                                                            | undefined;

                                                                                              property component

                                                                                              component?:
                                                                                              | React.ComponentType<RouteComponentProps<any>>
                                                                                              | React.ComponentType<any>
                                                                                              | undefined;

                                                                                                property exact

                                                                                                exact?: boolean | undefined;

                                                                                                  property location

                                                                                                  location?: H.Location | undefined;

                                                                                                    property path

                                                                                                    path?: Path | readonly Path[] | undefined;

                                                                                                      property render

                                                                                                      render?: ((props: RouteComponentProps<Params>) => React.ReactNode) | undefined;

                                                                                                        property sensitive

                                                                                                        sensitive?: boolean | undefined;

                                                                                                          property strict

                                                                                                          strict?: boolean | undefined;

                                                                                                            interface RouterChildContext

                                                                                                            interface RouterChildContext<Params extends { [K in keyof Params]?: string } = {}> {}

                                                                                                              property router

                                                                                                              router: {
                                                                                                              history: H.History;
                                                                                                              route: {
                                                                                                              location: H.Location;
                                                                                                              match: match<Params>;
                                                                                                              };
                                                                                                              };

                                                                                                                interface RouterProps

                                                                                                                interface RouterProps {}

                                                                                                                  property children

                                                                                                                  children?: React.ReactNode;

                                                                                                                    property history

                                                                                                                    history: H.History;

                                                                                                                      interface StaticContext

                                                                                                                      interface StaticContext {}

                                                                                                                        property statusCode

                                                                                                                        statusCode?: number | undefined;

                                                                                                                          interface StaticRouterContext

                                                                                                                          interface StaticRouterContext extends StaticContext {}

                                                                                                                            property action

                                                                                                                            action?: 'PUSH' | 'REPLACE' | undefined;

                                                                                                                              property location

                                                                                                                              location?: object | undefined;

                                                                                                                                property url

                                                                                                                                url?: string | undefined;

                                                                                                                                  interface StaticRouterProps

                                                                                                                                  interface StaticRouterProps {}

                                                                                                                                    property basename

                                                                                                                                    basename?: string | undefined;

                                                                                                                                      property children

                                                                                                                                      children?: React.ReactNode;

                                                                                                                                        property context

                                                                                                                                        context?: StaticRouterContext | undefined;

                                                                                                                                          property location

                                                                                                                                          location?: string | object | undefined;

                                                                                                                                            interface SwitchProps

                                                                                                                                            interface SwitchProps {}

                                                                                                                                              property children

                                                                                                                                              children?: React.ReactNode | undefined;

                                                                                                                                                property location

                                                                                                                                                location?: H.Location | undefined;

                                                                                                                                                  interface WithRouterStatics

                                                                                                                                                  interface WithRouterStatics<C extends React.ComponentType<any>> {}

                                                                                                                                                    property WrappedComponent

                                                                                                                                                    WrappedComponent: C;

                                                                                                                                                      Type Aliases

                                                                                                                                                      type ExtractRouteOptionalParam

                                                                                                                                                      type ExtractRouteOptionalParam<
                                                                                                                                                      T extends string,
                                                                                                                                                      U = string | number | boolean
                                                                                                                                                      > = T extends `${infer Param}?`
                                                                                                                                                      ? { [k in Param]?: U }
                                                                                                                                                      : T extends `${infer Param}*`
                                                                                                                                                      ? { [k in Param]?: U }
                                                                                                                                                      : T extends `${infer Param}+`
                                                                                                                                                      ? { [k in Param]: U }
                                                                                                                                                      : { [k in T]: U };

                                                                                                                                                        type ExtractRouteParams

                                                                                                                                                        type ExtractRouteParams<
                                                                                                                                                        T extends string,
                                                                                                                                                        U = string | number | boolean
                                                                                                                                                        > = string extends T
                                                                                                                                                        ? { [k in string]?: U }
                                                                                                                                                        : T extends `${infer _Start}:${infer ParamWithOptionalRegExp}/${infer Rest}`
                                                                                                                                                        ? ParamWithOptionalRegExp extends `${infer Param}(${infer _RegExp})${infer Modifier extends
                                                                                                                                                        | '?'
                                                                                                                                                        | '+'
                                                                                                                                                        | '*'
                                                                                                                                                        | ''}`
                                                                                                                                                        ? ExtractRouteOptionalParam<`${Param}${Modifier}`, U> &
                                                                                                                                                        ExtractRouteParams<Rest, U>
                                                                                                                                                        : ExtractRouteOptionalParam<ParamWithOptionalRegExp, U> &
                                                                                                                                                        ExtractRouteParams<Rest, U>
                                                                                                                                                        : T extends `${infer _Start}:${infer ParamWithOptionalRegExp}`
                                                                                                                                                        ? ParamWithOptionalRegExp extends `${infer Param}(${infer _RegExp})${infer Modifier extends
                                                                                                                                                        | '?'
                                                                                                                                                        | '+'
                                                                                                                                                        | '*'
                                                                                                                                                        | ''}`
                                                                                                                                                        ? ExtractRouteOptionalParam<`${Param}${Modifier}`, U>
                                                                                                                                                        : ExtractRouteOptionalParam<ParamWithOptionalRegExp, U>
                                                                                                                                                        : {};

                                                                                                                                                          type Omit

                                                                                                                                                          type Omit<T, K extends keyof T> = T extends any
                                                                                                                                                          ? Pick<T, Exclude<keyof T, K>>
                                                                                                                                                          : never;

                                                                                                                                                            type OmitNative

                                                                                                                                                            type OmitNative<T, K extends string | number | symbol> = {
                                                                                                                                                            [P in Exclude<keyof T, K>]: T[P];
                                                                                                                                                            };

                                                                                                                                                              type WithRouterProps

                                                                                                                                                              type WithRouterProps<C extends React.ComponentType<any>> =
                                                                                                                                                              C extends React.ComponentClass
                                                                                                                                                              ? { wrappedComponentRef?: React.Ref<InstanceType<C>> | undefined }
                                                                                                                                                              : {};

                                                                                                                                                                Package Files (1)

                                                                                                                                                                Dependencies (2)

                                                                                                                                                                Dev Dependencies (0)

                                                                                                                                                                No dev dependencies.

                                                                                                                                                                Peer Dependencies (0)

                                                                                                                                                                No peer dependencies.

                                                                                                                                                                Badge

                                                                                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/react-router.

                                                                                                                                                                • Markdown
                                                                                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/react-router)
                                                                                                                                                                • HTML
                                                                                                                                                                  <a href="https://www.jsdocs.io/package/@types/react-router"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>