【发布时间】:2018-05-02 19:13:59
【问题描述】:
这个问题想要弄清楚的很简单:
“我可以通过编程方式将道具从一个场景发送到另一个场景吗?如果可以,如何发送?”
下面我提供了一组示例代码,希望有人有知识一劳永逸地解决这个问题。
App.js 文件:
const Main = () => (
<main>
<Switch>
<Route exact path='/Job' component={Job}/>
<Route path='/Preview' component={Preview}/>
</Switch>
</main>
Job.js:
长话短说,一旦用户点击提交,文件就会接受输入和输出,这个函数被调用:
handleClick(){
//The state I wish to pass: this.state.propToPass
//my current implementation for moving to the correct scene:
this.props.history.push('/Preview')
}
Preview.js
constructor(props){
super(props)
//console.log(the prop that has been sent)
}
我将永远感激任何了解问题并能阐明我的困境的人。
非常感谢。
【问题讨论】:
标签: reactjs react-router react-router-v4 react-router-dom