【发布时间】:2017-08-31 15:58:43
【问题描述】:
我有一些用 react router v4 编写的嵌套路由,在导航组件中我有一个输入框。
在提交时,我需要在不同的路线上调用一个方法(在着陆组件上)并传递值。我找不到任何在 Route 中调用方法的示例。
欢迎使用带有数据和不同路线的导航的任何其他方式/解决方法。
我的路线:
return (
<div>
<Navigation callSearch = {this.callSearch.bind(this)} />
<Switch>
<Route path="/u/:slug" component={AuthorPage}/>
<Route path="/:location/:slug" component={PhotoDetails}/>
<Route path="/" component={Landing} />
</Switch>
</div>
)
在导航中我调用 callSearch() :
searchPhotos(e) {
e.preventDefault();
if(this.state.searchTerm) {
this.props.callSearch(this.state.searchTerm);
}
}
【问题讨论】:
-
使用 redux 作为状态管理器
标签: reactjs react-router react-router-v4