跳转拦截,不光使用在登录,例如某些需要次序加载的页面,除根目录外需要拦截,在meta中增加requireAuth:true。进入判断,
根据存在的session 判断。
routes: [
{
path: '/',
name: 'patientInfoAdd',
component: ()=>import ('@/views/patientInfoAdd.vue')
},
{
path: '/visitsIm',
name: 'visitsIm',
meta:{
requireAuth:true
},
component: ()=>import ('@/views/visitsIm.vue') //问诊过程
}
]
router.beforeEach((to, from, next) => {
if(to.meta.requireAuth){ //判断需不需要拦截这个地址
console.log(util.session('patientData'))
if (util.session('patientData')) {
next();
} else {
next({
path: '/'
})
}
}else{
next();
}
})