React 子组件 调用 this.props.history.push();发生报错的解决方案

可以通过父组件传给子组件history.push()的方式去解决 

父组件代码

 render() {
    return (
      <div className="homePage">
       <MyAppModal  history ={this.props.history}  />
      </div>
)
}

子组件的调用history.push()方法

 async openProject(index){

    return await  this.props.history.push('/myproject/'+index);
  }



猜你喜欢

转载自blog.csdn.net/u013040887/article/details/80948984