router.addRoutes(routes); //动态配置路由的API
router是项目中VueRouter的实例。参数routes是一个数组,数组元素是合法的路由配置对象。开发中可通过router.addRoutes()实现路由权限动态管理。
let newRoutes = [];
let about = { //接口返回路由信息
path: '/about',
name: 'About',
component: () => import('@/views/about.vue'),
children : []
};
let index = { //接口返回路由信息
path: '/index',
name: 'Index',
component: () => import('@/views/index.vue'),
children : []
};
newRoutes.push(about,index);
router.addRoutes(newRoutes); //添加到路由