这里的 /home 路径 需要权限访问
{
path: '/home',
name: '主页',
component: Home,
hidden: true,
//需要登录,才能访问
meta: {
requireAuth: true
}
在main.js中配置
router.beforeEach((to, from, next)=> {
if (to.name == 'Login') {
next();
return;
}
var name = store.state.user.name;
if (name == '未登录') {
if (to.meta.requireAuth || to.name == null) {
//将跳转的路由path作为参数,登录成功后跳转到该路由
next({path: '/', query: {redirect: to.path}})
} else {
next();
}
}
}
)