导航守卫

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; let zhi = this.$route.params;
console.log(zhi); console.log(zhi);
} }
},
mounted(){
console.log(this.$route,"组建内")
} }
} }
</script> </script>

View File

@ -8,24 +8,43 @@ const router = new VueRouter({
routes: [{ routes: [{
path:"/index", path:"/index",
component:index, component:index,
meta:["user","admin"],
children:[{ children:[{
path:"table", path:"table",
meta:["user","admin"],
component: () => import("../pages/table.vue") component: () => import("../pages/table.vue")
},{ },{
path:"list", path:"list",
meta:["admin"],
component: list component: list
}] }]
},{ },{
path:"/list", path:"/list",
name:"list", name:"list",
component:list component:list,
meta:["admin"],
},{ },{
path:"/login", path:"/login",
meta:["user","admin"],
component: ()=> import("../pages/login.vue") component: ()=> import("../pages/login.vue")
},{ },{
path:"*", path:"*",
meta:["user","admin"],
component: ()=> import("../pages/404.vue") 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 export default router