鍍金池/ 問答/HTML/ vue-router中導航守衛(wèi)中next 無法訪問當前子路由

vue-router中導航守衛(wèi)中next 無法訪問當前子路由

圖片描述vue-router中導航守衛(wèi)中next 無法訪問當前子路由
vue-router代碼

    {
        path: '/admin',
        component: Ladmin,
        meta:{auth:true},
        children: [
            {
                path: '',
                component: Admin,
            },
            {
                path: 'login',
                component: Login,
            },
        ]
    },

導航守衛(wèi)代碼

router.beforeEach((to, from, next) => {
    if(to.matched.some( m => m.meta.auth)){
        if(store.state.isLogin == true){
            next()
        }else{
            next('/admin/login')
        }
    }else{
        next()
    }
})

最后這樣卻可以了

{
            path: '/admin',
            component: Ladmin,
            meta:{auth:true},
            children: [
                {
                    path: '',
                    component: Admin,
                },
            ]
        },
        {
            path: '/admin/login',
            component: Login,
        }

這到底怎么回事 為什么啊 求解答

回答
編輯回答
刮刮樂

beforeEach必須要執(zhí)行了next()才會執(zhí)行下面的代碼,你設置導航路由鉤子時那個store.state.isLogin是為true嗎

2017年7月19日 10:49