main.js中
router.beforeEach((to, form, next) => {
// to要跳转到的路径
// from从哪个路径来
// next往下执行的回调
// 在localStorage中获取信息
if (to.name !== 'login') {
store.dispatch('getLayoutConfigInfo').then(() => {
next();
});
} else {
next();
}
let a = localStorage.getItem('username')
let b = ['pageConfig','indexConfig','classConfig','stationConfig']
if (a!='admin'&&b.includes(to.name)) {
//满足条件进行判断 跳转
ElementUI.Message.error('无权限访问此页面')
next({
path:"/fixture"
})
} else {
next();
}
});
router.js
{
path: '/',
redirect: '/login'
},
{
path: '/login',
name: 'login',
component: () => import('@views/login/login')
},
{
path: '/home',
name: 'home',
redirect: '/fixTure',
component: Home,
}