browserHistory.push not working in react

自闭症网瘾萝莉.ら 提交于 2021-02-20 02:59:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!