用户收到一封带有邀请码的电子邮件,例如 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>
不支持直接传参的方式。
关于reactjs - React-Router 4,使用动态路径重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46683886/