[英]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.