I'm looking for a way in React to redirect after a successful login with success message. After the login, another ponent should show a success message, so how do I inform it that the redirect was after successful login? I once did that with flash messages, but that solution did not use react-router and had full page refreshes.
I am now using react-router, and am curious whether there is a react-router way to pass state/message to another route when redirecting? I am redirecting with:
browserHistory.push('/')
so I've tried:
browserHistory.push({
pathname: '/',
state: {
message: "my message"
}
});
But target ponent's this.state
remained null. Is there a way to achieve what I want using react-router's own API? Or maybe I'm trying to solve this problem incorrectly?
I'm looking for a way in React to redirect after a successful login with success message. After the login, another ponent should show a success message, so how do I inform it that the redirect was after successful login? I once did that with flash messages, but that solution did not use react-router and had full page refreshes.
I am now using react-router, and am curious whether there is a react-router way to pass state/message to another route when redirecting? I am redirecting with:
browserHistory.push('/')
so I've tried:
browserHistory.push({
pathname: '/',
state: {
message: "my message"
}
});
But target ponent's this.state
remained null. Is there a way to achieve what I want using react-router's own API? Or maybe I'm trying to solve this problem incorrectly?
1 Answer
Reset to default 5I've found an answer myself, the method I tried does indeed work, but the pushed state is received from:
this.props.location.state
in target ponent.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744937739a4602129.html
评论列表(0条)