问题
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.
回答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);
来源:https://stackoverflow.com/questions/48084132/browserhistory-push-not-working-in-react