0

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.

Geek_To_Learn
  • 1,816
  • 5
  • 28
  • 48
  • Why are you not using link for the same? Link is like anchor tag. https://knowbody.github.io/react-router-docs/api/Link.html – learner Jan 03 '18 at 20:10
  • which version of `react-router` are using? `browserHistory` was removed in the latest `react-router` (v.4), so I am guessing it is an old version. is it a limitation of your project that you are not using the latest? – margaretkru Jan 03 '18 at 21:40

1 Answers1

1

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);
h-des
  • 767
  • 5
  • 9