const about = {    //接口返回路由信息
  path: '/about',
  name: 'About',
  component: () => import('./views/About.vue')
};
router.addRoute(about); //添加到路由

添加多个的话就需要遍历了。它本身其实是数组。

这里我们只需要component的内容。 

function routerPackag(routers:any) {
  if (routers) {
    routers.filter((itemRouter:any) => {
      if (itemRouter.component != "Layout") {
        router.addRoute('home',{ //home是父组件 add-route添加进父组件chilren里
          path: `${itemRouter.path}`,
          name: itemRouter.name,
          meta: {
            title: itemRouter.name,
          },
          component: () => import(`../views/${itemRouter.component}`),
        })
      }
      if (itemRouter.children && itemRouter.children.length) {
        routerPackag(itemRouter.children)
      }
      return true
    })
  }
}

Logo

前往低代码交流专区

更多推荐