欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue路由守卫 beforeEach(全局前置守卫)

程序员文章站 2022-03-24 18:01:45
...
vueRouter.beforeEach(async (to, from, next) => {
    if (to.path == '/login') {
        let nav = JSON.parse(localStorage.getItem("navMenu"))[0]
        console.log("to.path", to.path);
        // nav.children?
        let napath = nav.children ? nav.children[0].path : nav.path
        console.log("napath", napath);
        console.log("getisReg", store.state.getisReg);
        if (store.state.getisReg) {
            next()
        } else {
            next({
                path: napath
            })
        }

    } else {
        next()
    }

})