This commit is contained in:
2021-01-26 16:56:54 +08:00
parent 722ab517b0
commit 0bb48a9720
5 changed files with 204 additions and 18 deletions

View File

@@ -1,10 +1,20 @@
import Router from "vue-router"
import store from "@/store/index.js"
// import store from "@/store/index.js"
let router = new Router({
routes:[
{
path:"/",
component:() => import("../views/index.vue")
component:() => import("../views/index.vue"),
children:[
{
path:"list",
component: () => import("@/views/list.vue")
},
{
path:"add",
component: () => import("@/views/add.vue")
}
]
},
{
path:"/login",
@@ -13,15 +23,19 @@ let router = new Router({
]
})
router.beforeEach((to, from, next) => {
console.log(to.path,store.state.quanxian)
if(store.state.quanxian){
next()
}else if(to.path != "/login"){
router.push("/login")
}else{
next()
}
// router.beforeEach((to, from, next) => {
// if(store.state.quanxian){
// next()
// }else if(to.path != "/login"){
// router.push("/login")
// }else{
// next()
// }
// })
// 路由守卫可以写多个 只有都执行了next 才跳转
router.beforeEach((to,from,next) => {
console.log(to)
next()
})
export default router