Geek_To_Learn
Geek_To_Learn

Reputation: 1956

browserHistory.push not working in react

I am very new to reactJs. I am trying to change the tab on click of button. For this I am using browserHistory.

Problem here is url is getting changed but component is not getting rendered. Couldn't understand this.

browserHistory.push("/personalInfo"); 

This is how I am trying to change the tab. Url is getting changed to http://localhost:3000/personalInfo. But component is not rendered, when I refresh the browser, it's getting changed.

Upvotes: 0

Views: 1970

Answers (1)

h-des
h-des

Reputation: 865

Use withRouter

import React, { Component } from "react";
import {withRouter} from "react-router-dom";

class MyComponent extends Component {

  sampleFunction() {
    this.props.history.push("/personalInfo");
  }

}
export default withRouter(MyComponent);

Upvotes: 1

Related Questions