{
name: "登陆",
path: '',
meta: {
title:'登陆',
requireAuth: false, // 添加该字段,表示进入这个路由是需要登录的。默认是false
},
component: resolve => require(['@/components/login/login'], resolve)
},
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record. meta.requireAuth)){ // 判断该路由是否需要登录权限,在路由里面要添加 这个属性if (!localStorage.getItem("token")) { // 判断当前的token是否存在。如果登录就是有token的。没有就代表没登录
next({
path: '', 因为我登录的上面写的就是空,所以这里也是空
query: {redirect: to.fullPath} // 将跳转的路由path作为参数,登录成功后跳转到该路由
})
}
else {
next();
}
}
else {
next();
}
});