Dan*_*Dan 7 reactjs react-router
我有一个注册表单,在用户注册后,它将重定向到电子邮件确认页面(/确认),用户输入我通过电子邮件发送的确认码.当用户提交确认代码时,我想将代码和用户的电子邮件发送到服务器端.
我的注册表单代码(简化):
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(){ ...
Run Code Online (Sandbox Code Playgroud)
我不想在我的路径上添加任何参数.
我怎样才能this.state.email
转到确认页面?
Dan*_*Dan 25
我想到了.
this.context.router.push({
pathname: '/confirmation',
state: {email: this.state.email}
})
Run Code Online (Sandbox Code Playgroud)
和访问状态:
this.props.location.state.email
Run Code Online (Sandbox Code Playgroud)
我在没有上下文对象的情况下传递数据的方法是使用历史记录道具,
this.props.history.push({
pathname:"/shopdetail",
state:{
key:"value"
}
});
Run Code Online (Sandbox Code Playgroud)
在ShopDetail组件中,您可以访问以下对象:
this.props.location.state.key
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17786 次 |
最近记录: |