Ich verwende React-Router-2. Ich möchte nach erfolgreicher Anmeldung oder nach einer bestimmten Aktion programmgesteuert auf eine Seite umleiten.Redirect auf eine Seite programmgesteuert in React-Router 2
ist Meine Route-Datei wie folgt (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 Haken
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')
}
}
Ich möchte Armaturenbrettcomponent
von Anmeldungcomponent
nach umleiten erfolgreicher Login.