import store from '../store/store.js'; const staticMuen = [ { path: '/msg', component: () => import(/* webpackChunkName: "messages" */ '@views/messages'), meta: { title: '消息中心' } }, { path: '/403', component: () => import(/* webpackChunkName: "404" */ '@views/errorPage/403.vue'), meta: { title: '403' } }, { path: '/404', component: () => import(/* webpackChunkName: "404" */ '@views/errorPage/404.vue'), meta: { title: '404' } }, { path: '*', redirect: '/404' } ]; //路由格式 // 自定义路由文件 const setListMunt = (arrList, item) => { let newOb = {}; newOb = { path: `/${item.linkPath}`, component: () => import(`@/views/${item.linkPath}.vue`), meta: { title: item.name } }; arrList.push(newOb); }; const dimension = (arrList, arr) => { arr.forEach((item, index) => { if (!!item.children) { dimension(arrList, item.children); } else { setListMunt(arrList, item); } }); }; //添加路由 const AddRt = (router, dynamicMuenList) => { let NEWdynamicMuenList = [...dynamicMuenList, ...staticMuen]; if (NEWdynamicMuenList.length !== 0) { NEWdynamicMuenList.forEach((item) => { router.options.routes[0].children.push(item); }); router.addRoutes(router.options.routes); } }; export const funcRouter = (arr, data, router) => { dimension(arr, data); store.commit('setMenuList', data); AddRt(router, arr); };