I've set up browserHistory on a router with this (react-router 2.0):
import { browserHistory } from 'react-router'
function requireAuth(nextState, replace) {
if (!services.auth.loggedIn()) {
replace({
pathname: '/login',
state: { nextPathname: nextState.location.pathname }
})
}
}
export default (store) => (
<Router history={browserHistory}>
<Route path='/' component={AppLayout}>
<Route path="login" component={LoginContainer} />
<Route path="map" component={MapContainer} onEnter={requireAuth} />
</Route>
</Router>
);
I'm then trying to use browserHistory in react-router to programmatically route to a new page from a view, ala:
import { browserHistory } from 'react-router'
...
browserHistory.push('/map');
This changes the URL to /map but does not render the components in that route. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…