导航守卫

This commit is contained in:
theluyuan 2021-09-01 09:43:04 +08:00
parent aacc01f72b
commit b334f528cf
2 changed files with 24 additions and 2 deletions

View File

@ -18,6 +18,9 @@ export default {
let zhi = this.$route.params;
console.log(zhi);
}
},
mounted(){
console.log(this.$route,"组建内")
}
}
</script>

View File

@ -8,24 +8,43 @@ const router = new VueRouter({
routes: [{
path:"/index",
component:index,
meta:["user","admin"],
children:[{
path:"table",
meta:["user","admin"],
component: () => import("../pages/table.vue")
},{
path:"list",
meta:["admin"],
component: list
}]
},{
path:"/list",
name:"list",
component:list
component:list,
meta:["admin"],
},{
path:"/login",
meta:["user","admin"],
component: ()=> import("../pages/login.vue")
},{
path:"*",
meta:["user","admin"],
component: ()=> import("../pages/404.vue")
}]
})
// const shenfen = "admin" user
// 0
// 1
// 登录状态 本地有没有登录的信息
const shenfen = "user"
router.beforeEach((to,form,next)=>{
console.log(to)
if(to.meta.includes(shenfen)){
next()
}else{
next("/login")
}
// 路由源信息
})
export default router