最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to redirect with react-router and send a message - Stack Overflow

programmeradmin1浏览0评论

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?

Share Improve this question asked May 22, 2016 at 10:26 Vincas StonysVincas Stonys 1,1351 gold badge16 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I'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.

发布评论

评论列表(0)

  1. 暂无评论