0
export default class Root extends React.Component{
constructor(props) {
super(props);
}
dealsCallBack = (dealListFromHome)=>{
console.log("deals from home"+dealListFromHome);
}
render(){
return(
<div>
<Header/>
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/mall/:id" component={MallDetail}/>
<Route path="/home/:location" render={(props) => (<Home passDealsToRoute ={this.dealsCallBack} {...props}/>)} />
<Route exact path="/about" component={About}/>
</Switch>
<Footer/>
</div>
);
}
}
如何从组件主页访问passDealsToRoute? this.props。 passDealsToRoute(theList)不起作用。反应路由器4在路线中传递参数
你的要求是一样的这个问题https://stackoverflow.com/questions/44255415/react-router-4-1-1-this-props-route-is-undefined/44255850#44255850,唯一的区别是主组件在两个不同的路由中被调用,第一个组件不提供该道具,因此在这种情况下可能会失败。试着在使用前提供一个支票 –
我的版本是一样的4.1.1,但我没有得到道具。 passDealsToRoute,这也是一个回调。 –
@ShubhamKhatri,这就是为什么我使用精确的匹配确切的网址(都带有参数和W/O PARAMS) –