I am currently using "react-router": "^2.4.0" in my chat application and am confused how to redirect when there is no user. I don't think redirection works in "^2.4.0" .
Should I use onEnter hooks in my chat ?
Something like that:
<Route path="chat" component={Chat} onEnter={Chat.willTransitionTo}/>
routes.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'); } }
source share