[英]React-Router 4, Redirect with dynamic path
用户收到一封包含邀请代码的电子邮件,例如http://website.com/invitation/%s
,其中%s
是邀请代码。
现在,我想在我的应用程序中重定向该URL,但保留邀请代码,例如:
<Redirect from="/invitation/:code" to="/auth/register/:code" />
因此,当用户单击电子邮件中的链接时:
http://website.com/invitation/2abc433
他将被转到:
http://website.com/auth/register/2abc433
不幸的是,使用上述重定向组件,他被转移到
http://website.com/auth/register/:code
您可以为此使用无状态组件:
<Route exact path="/invitation/:code" render={props => (
<Redirect to={`/auth/register/${props.match.params.code}`/>
)}/>
<Redirect>
不支持直接传递参数的方法。
在ES6中进行以下一行
<Redirect from="/invitation/:code" to="/auth/register/:code" />
对此
<Redirect from={`/auth/invitation/${code}`} to={`/auth/register/${code}`} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.