我目前正在"react-router": "^2.4.0"
我的聊天应用程序上使用,并且对如何在没有用户时重定向感到困惑。我不认为重定向在"^2.4.0"
.
我应该onEnter
在我的聊天路径上使用钩子吗?
像这样的东西:
<Route path="chat" component={Chat} onEnter={Chat.willTransitionTo}/>
路由.js
<Route path="/" component={App} >
<IndexRoute component={Chat} />
<Route path="chat" component={Chat} />
<Route path="login" component={Login} />
</Route>
Chat.jsx
static willTransitionTo(transition){
var state = ChatStore.getState();
if(!state.user){
transition.redirect('/login');
}
}