vue路由动态配置

	router.beforeEach((to, from, next) => {
    	if(to.path != "/login" && store.getters.menu.length == 0 && store.getters.access_token){
        store.dispatch('GetMenu').then((res) => {
            if(res){
                for (let index = 0; index < res.length; index++) {
                    res[index].component = () => import('@/' + res[index].routeView)
                }
                router.addRoutes([
                    {
                        path: '/',
                        redirect: '/dashboard',
                        component: () => import('@/views/dashboard/Index'),
                        children: res
                    }
                ])
                router.addRoutes([
                    {
                        path: '*', // 页面不存在的情况下会跳到404页面
                        redirect: '/404',
                    }
                ])
            }
        })
    }

猜你喜欢

转载自blog.csdn.net/weixin_39308542/article/details/107176283