父组件App中有个callback方法想要传递给子组件Objective,不使用ReactRouter时可以通过props传递
//App中
callback=()=>{console.log(1)};
<Objective callback={this.callback}></Objective>
//Objective中
this.props.callback();//1
但是启用ReactRouter后,怎么给Objective组件传递方法呢
直接这么写是获取不到callback方法的
//App中
callback=()=>{console.log(1)};
<Route path="/objective" component={Objective} callback={this.callback}></Route>
//Objective中
this.props.callback();//callback不存在
这是最简单直接的方式