[英]ReactJS react-router
I'm developing am application with ReactJS, but I have a problem. 我正在使用ReactJS开发应用程序,但我遇到了问题。
That's my Router 那是我的路由器
<Router history={browserHistory}>
<Route name="Home" path="/" component={App}>
<IndexRoute component={Home}></IndexRoute>
<Route name="Stores" path='stores' component={Stores}>
<Route name="List" path='/stores/list' component={StoreList}></Route>
<Route name="Create" path='/stores/create' component={StoreCreate}> </Route>
</Route>
<Route name="404: No Match for route" path="*" component={NoMatch} />
</Route>
</Router>
The route to Stores Don't exists. 商店的路线不存在。 But, when I click in the link to this route, they must redirect do "StoreList"
但是,当我点击此路线的链接时,他们必须重定向做“StoreList”
<Route name="Stores" path='stores' component={Stores}>
So I did: 所以我做了:
class Stores extends React.Component {
componentWillMount() {
this.setUrlParameters();
}
setUrlParameters() {
if (!this.props.children) {
this.context.router.push({
pathname: '/stores/list',
query: {
page: 1,
limit: 10
}
});
}
}
render() {
return (this.props.children);
}
}
The first time that I click in the link, they do perfect the redirect. 我第一次点击链接时,他们确实完善了重定向。 But if I click again, they not call componentWillMount and the redirect doesn't exec.
但是,如果我再次单击,它们不会调用componentWillMount ,并且重定向不会执行。
Can someone help me? 有人能帮我吗?
尝试在componentDidUpdate中调用this.setURlParameters()而不是componentWillMount
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.