在反應路由器 V5 中,您可以使用
history.push('/login?redirect=other_page')
將用戶重定向到'/login'或'/other_page'(如果已經登錄)
react router V6 和 useNavigate 的等價物是什么?
navigate('/login?redirect=other_page')
沒有按預期作業。
當用戶登錄時,它回傳路徑'/login/other_page'而不是'/other_page'.
uj5u.com熱心網友回復:
react-router-domv6 使用絕對和相對導航。我的猜測是 path'/login?redirect=other_page'的redirectqueryString 值是"other_page"并且你從 "/login"那里重定向,即相對于從"/login"到"/login/other_path"。絕對導航和相對導航的區別在于引導"/"字符。絕對路徑以相對路徑開頭,"/"而相對路徑不以開頭。
您可以嘗試發送絕對路徑'/login?redirect=/other_page'。
navigate('/login?redirect=/other_page');
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/414880.html
標籤:
