加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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.state.email传递给确认页面?

解决方法

我想到了.

this.context.router.push({
     pathname: '/confirmation',state: {email: this.state.email}  
 })

和访问状态:

this.props.location.state.email

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读