reactjs – 如何在React中重定向到另一个路由时传递状态/道具?
发布时间:2020-12-15 20:18:44 所属栏目:百科 来源:网络整理
导读:我有一个注册表单,在用户注册后,它将重定向到电子邮件确认页面(/确认),用户输入我通过电子邮件发送的确认码.当用户提交确认代码时,我想将代码和用户的电子邮件发送到服务器端. 我的注册表单代码(简化): constructor(props){ super(props); this.state = { e
我有一个注册表单,在用户注册后,它将重定向到电子邮件确认页面(/确认),用户输入我通过电子邮件发送的确认码.当用户提交确认代码时,我想将代码和用户的电子邮件发送到服务器端.
我的注册表单代码(简化): constructor(props){ super(props); this.state = { email: '',password: '',errors: {},} } handleSubmit(e){ e.preventDefault(); this.props.userSignup(this.state).then( () => { this.context.router.push({ pathname: '/confirmation' }) },) } render(){ ... 我不想在我的路径上添加任何参数. 解决方法
我想到了.
this.context.router.push({ pathname: '/confirmation',state: {email: this.state.email} }) 和访问状态: this.props.location.state.email (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- objective-c – 测试一个已经重构的方法(分成多个方法)?
- c# – 针对MS Access的LINQ asp.net页面.
- c# – 为什么在setter之前定义getter(编码约定)
- 正则表达式转NFA
- 如何在c#中使用PDFSharp在pdf中嵌入数字签名?
- flash – 新Chrome更新会导致wmode = transparent
- ruby中Datetime.civil和Datetime.new有区别吗?
- sax错误:org.xml.sax.SAXParseException: Content is not
- ajax获取kindeditor编辑器内容中的图片
- Cocos2d-x屏幕适配之Sprite绘制原理