reactjs 重定向至“用户完成注册后登录”诊断树

cyej8jka  于 2022-12-03  发布在  React
关注(0)|答案(2)|浏览(104)

重定向、导航和重定向对我不起作用
我希望重定向到登录. enter image description here

e0uiprwp

e0uiprwp1#

在路由之前,你必须检查本地存储是否包含auth_token如果auth_token不存在,然后使用history.push(“login path”)重定向到登录。

if(localStorage.getItem(key of that auth_token while setting){
history.push(login route)
}
vuktfyat

vuktfyat2#

使用函数顶部的useNavigate,然后... Sulotion

相关问题