React Router class tools
    Preparing search index...

    Function withRouter

    • Type Parameters

      Parameters

      • Class: C
      • Optionalcontext: ClassDecoratorContext<C>

      Returns {
          displayName: string;
          prototype: __type<any, any>;
          WrappedComponent: C;
          getDerivedStateFromError(error: Error): void;
          getDerivedStateFromProps(
              nextProps: Readonly<P>,
              prevState: Readonly<{}>,
          ): {};
          new (props: P, context?: any): __type<P, C>;
      } & C

        • new (props: P, context?: any): __type<P, C>
        • Parameters

          • props: P
          • Optionalcontext: any

            Value of the parent Context specified in contextType.

          Returns __type<P, C>

      • displayName: string
      • prototype: __type<any, any>
      • WrappedComponent: C
      • getDerivedStateFromError: function
      • getDerivedStateFromProps: function
      import { Component } from 'react';
      import { RouteComponentProps, withRouter } from 'react-router-class-tools';

      @withRouter
      export class PageWithRouterDecorator extends Component<RouteComponentProps> {
      render() {
      const { location, match, query } = this.props;

      return (
      <pre>{JSON.stringify({ location, match, query }, null, 4)}</pre>
      );
      }
      }
      import { Component } from 'react';
      import { RouteComponentProps, withRouter } from 'react-router-class-tools';

      export default withRouter(class PageWithRouterFunction extends Component<RouteComponentProps> {
      render() {
      const { location, match, query } = this.props;

      return (
      <pre>{JSON.stringify({ location, match, query }, null, 4)}</pre>
      );
      }
      }