main.js编写路由守卫函数
router.beforeEach((to, from, next) => { //路由守卫
if (to.name == 'Login') {
sessionStorage.clear() //返回到登录界面,清空所有session
next()
}
else if (to.meta.requiresAuth) {
console.log(to.name)
var res = sessionStorage.getItem('islogin')
if (res && res.result == true) {
next()
}
else {
if (res == null) {
next({ path: '/' })
}
else {
next()
}
}
}
else {
next();
}
})
router.js设置路由的登录可见性 meta: { requiresAuth: true }
const routes = [
{
path: '/',
name: 'Login',
component: () => import('../views/Login')
},
{
path: '/flow',
name: 'flow',
components:{
top:() => import('../components/common/TopHeader.vue'),
default:() => import('../views/drawflow/G6Editor/index')
},
meta: { requiresAuth: true }
}
}