反应路由器4在路由中传递参数
react router 4 passing params in Route
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) 不工作。
constructor(props) {
super(props);
this.dealsCallBack = this.dealsCallBack.bind(this);
}
得到答案。
this.dealsCallBack = this.dealsCallBack.bind(this);
此行解决了问题。
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) 不工作。
constructor(props) {
super(props);
this.dealsCallBack = this.dealsCallBack.bind(this);
}
得到答案。
this.dealsCallBack = this.dealsCallBack.bind(this);
此行解决了问题。