I am following the auth flow example to do my own project:
I got a sign page and a user center page.
user should sign in to access the user center page.
user center route config:
module.exports = {
onEnter: redirectToSignin,
childRoutes: [
{
path: 'usercenter',
getComponent: function(location, cb) {
require.ensure([], function(require) {
cb(null, require('../components/UserCenter.js'));
});
}
}
]
}
and I go to /usercenter, the browser redirect to /signin, it works.
but I always get null when access this.props.location.state in sign in component
_handleSubmit: function(e) {
e.preventDefault();
console.log(this.props.location.state); // null ???
return false;
}
so I can not get location.state.nextPathname to let user redirect after sign in.
Thanks for your question!
We want to make sure that the GitHub issue tracker remains the best place to track bug reports and feature requests that affect the development of React Router.
Questions like yours deserve a purpose-built Q&A forum. Could you post this question to Stack Overflow with the tag #react-router? https://stackoverflow.com/questions/ask?tags=react-router.
We also have an active and helpful React Router community on Reactiflux, which is a great place to get fast help with React Router and with the rest of the React ecosystem. You can join at https://discord.gg/0ZcbPKXt5bYaNQ46.
Excuse me, sometimes I just do not know whether it is a bug or a usage mistake
I have the same error, my redirect function is:
replaceState({ nextPathname: nextState.location.pathname }, '/auth');
In auth route, location.state doesn't exists
Same issue, any solutions yet?
I'm using react-router 2.0
I fixed my problem.
the "redirectToSignIn" function can be like this
redirectToSignin: function(nextState, replace) {
if (!isSignedIn()) {
replace({
pathname: '/signin',
state: {
nextPathname: nextState.location.pathname
}
});
}
},
and after successfully sign in
this.context.router.replace(this.props.location.state.nextPathname);