可以通过父组件传给子组件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);
}
本文介绍了一种在React应用中从父组件向子组件传递并使用history.push方法的方法,以实现导航到新路由的功能。具体实现方式为:父组件将props中的history对象传递给子组件,在子组件中调用history.push来导航到指定路径。
2305

被折叠的 条评论
为什么被折叠?



