2016-10-04 22 views
4

我有一個註冊表單,用戶註冊後,它將重定向到用戶輸入通過電子郵件發送的確認碼的電子郵件確認頁面(/確認)。當用戶提交確認碼時,我想將代碼和用戶的電子郵件發送到服務器端。如何在React中重定向到其他路線時傳遞狀態/道具?

我的申請表單的代碼(簡化):

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(){ ... 

我不想任何PARAMS添加到我的路徑。
如何將this.state.email傳遞給確認頁?

+0

使用反應路由器https://github.com/ReactTraining/react-router –

回答

10

我想通了。

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

和訪問狀態是:

this.props.location.state.email 
+0

非常感謝你張貼,也有同樣的問題,你的答案 –

+0

@ Full-Hybrid沒問題! – Dan

+0

值得注意的是,上下文並不穩定或在React中推薦。 –

相關問題