I'm developing am application with ReactJS, but I have a problem.
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"
<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.
Can someone help me?
尝试在componentDidUpdate中调用this.setURlParameters()而不是componentWillMount
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.