Ilja Ilja - 1 year ago 253
Javascript Question

this.props.history is deprecated (react-router)

I was trying to programatically navigate to a different page like so

it worked, but I got a deprecation warning in console saying:

Warning: [react-router] props.history and context.history are deprecated. Please use context.router.
more about it here

Afterwards I tried to use this new method like so
but this doesn't seem to be the right approach.

Answer Source

Maybe you did forget to define the router as contextType? Assuming you have a component like:

class YourComponent extends React.Component {
      render() {
        return <div></div>;

You have to define the contextTypes as follows right beneath your component:

YourComponent.contextTypes = {
  router: React.PropTypes.object.isRequired