VueRouter中存储路由的参数是什么?-灵析社区

桃子爱吃玉米

在路由导航守卫中,router.addRoute(getMenuRoutes(menus, homePath));这段代码添加了动态路由,VueRouter存储的路由在哪个参数里?我在router.options.routes中只找到了静态路由,没发现添加的动态路由 ![image.png](https://wmlx-new-image.oss-cn-shanghai.aliyuncs.com/images/20241104/5430a72e67bc2500ff04f4926675578e.png) const router = new VueRouter({ routes, // mode: 'history', mode: 'hash', scrollBehavior() { return { y: 0 }; } }); router.beforeEach(async (to, from, next) => { if (!from.path.includes(REDIRECT_PATH)) { NProgress.start(); } // 判断是否登录 if (getToken()) { // 还未注册动态路由则先获取 if (!store.state.user.menus) { store .dispatch('user/fetchUserInfo') .then(({ menus, homePath }) => { if (menus) { router.addRoute(getMenuRoutes(menus, homePath)); console.log(router); next({ ...to, replace: true }); } }) .catch((e) => { // console.error(e); next(); }); } else { next(); } } else if (WHITE_LIST.includes(to.path)) { next(); } else { } }); * * * ![image.png](https://wmlx-new-image.oss-cn-shanghai.aliyuncs.com/images/20241104/fd06c2d0368d87da98f62ca31b6c76f3.png) if (menus) { router.addRoute(getMenuRoutes(menus, homePath)); console.log(router.getRoutes()); console.log(router); next({ ...to, replace: true }); }

阅读量:13

点赞量:0

问AI
请查看getMenuRoutes函数,如果是框架的话,大部分会存在嵌套路由的情况,你点开routes查看一下,是否存在children数组