简体   繁体   English

导航到其他路线时清除redux状态

[英]clear state of redux when navigating to different route

I have this in my login.js, I tried to use wrong password to trigger it. 我的login.js中有此密码,我尝试使用错误的密码来触发它。

{this.props.msg && <MessageBanner content={this.props.msg} />}

But when the message appear, I try to navigate to signup.js, which also have the same 但是,当消息出现时,我尝试导航至signup.js,该文件也具有相同的功能

{this.props.msg && <MessageBanner content={this.props.msg} />}

The message isn't go away. 该消息不会消失。 Or I'm in signup.js page, make the error appear, I click back on the browser, the error did not disappear. 或者我在signup.js页面中,使错误出现,我在浏览器上单击回来,该错误没有消失。

Anyway to clear a state when navigating with react-router? 无论如何在使用react-router导航时清除状态?

It sounds like you need correctly setup a "toggle" system to show this error message you have... 听起来您需要正确设置“切换”系统才能显示此错误消息...

Does you MessageBanner have a close button? 您的MessageBanner是否有关闭按钮? If so you would want to attach a 如果是这样,您将希望附加一个

onClick={this.setState=({toggleErrorMessage: !this.state.toggleErrorMessage})}

//on click reverse whatever this.state.toggleErrorMessage currently is... //so if currently true, after clicking will be false. //点击反转时,此this.state.toggleErrorMessage当前是什么... //因此,如果当前为true,则单击后为false。

Then you could do something more like this. 然后,您可以做更多类似的事情。

{this.state.toggleErrorMesage ? this.props.msg && <MessageBanner content={this.props.msg} /> : undefined }

//if toggleErrorMessage is true, show msg and banner... //如果toggleErrorMessage为true,则显示味精和横幅...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM