I am using reaction-router-2 . I want to redirect to the page programmatically after a successful login or after performing some actions.
My route file looks like this ( routes.js )
<Route path="/" component={App}> <IndexRoute component={Home}/> <Route path="/login" component={Login} onEnter={redirectToDashboard}/> <Route path="dashboard" component={Dashboard} onEnter={redirectToLogin}/> </Route>
onEnter .
function redirectToLogin(nextState, replace) { // Perform some authentication check if (!loggedIn) { replace({ pathname: '/login', state: { nextPathname: nextState.location.pathname } }); } } function redirectToDashboard(nextState, replace) { // Perform some check if already authenticated if (loggedIn) { replace('/dashboard') } }
I want to redirect to the Dashboard component from the Login component after a successful login.
javascript reactjs react-router
Witvault
source share