客户端token失效的情况下,点击其他路由要自动跳转到登陆页
实现方式: 在路由文件router/index.js文件下面的登录路由中添加一个对公的条件,然后在beforeEach钩子函数中添加条件判断条件:
{
path
: "/",
redirect
: "/login",
},{
path
: "/login",
name
: "login",
component
: () => import("../views/login"),
meta
: { isPublic
: true },
},...
router
.beforeEach((to
, from, next
) => {
if (!to
.meta
.isPublic
&& !sessionStorage
.getItem("token")) {
next("/");
}
next();
});
转载请注明原文地址: https://lol.8miu.com/read-5362.html