routes.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { menuToRoutes, eachTreeData } from 'ele-admin';
  2. import { HOME_PATH, LAYOUT_PATH, REDIRECT_PATH } from '@/config/setting';
  3. import EleLayout from '@/layout/index.vue';
  4. import RedirectLayout from '@/components/RedirectLayout';
  5. import { iframeMixins } from '@/utils/iframe-mixin';
  6. /**
  7. * 静态路由
  8. */
  9. export const routes = [
  10. {
  11. path: '/login',
  12. component: () => import('@/views/login/index.vue'),
  13. meta: { title: '登录' }
  14. },
  15. {
  16. path: '/forget',
  17. component: () => import('@/views/forget/index.vue'),
  18. meta: { title: '忘记密码' }
  19. }
  20. // 404
  21. // {
  22. // path: '*',
  23. // component: () => import('@/views/exception/404/index.vue')
  24. // }
  25. // {
  26. // path: '/system/role',
  27. // component: () => import('@/views/system/role/index.vue'),
  28. // meta: { title: '编码信息' }
  29. // }
  30. ];
  31. /**
  32. * 添加动态路由
  33. * @param menus 菜单数据
  34. * @param homePath 菜单数据的第一个页面地址
  35. */
  36. export function getMenuRoutes(menus, homePath) {
  37. const routes = [
  38. // 用于刷新的路由
  39. {
  40. path: REDIRECT_PATH + '/:path(.*)',
  41. component: RedirectLayout,
  42. meta: { hideFooter: true }
  43. }
  44. ];
  45. // 路由铺平处理
  46. eachTreeData(
  47. menuToRoutes(menus, getComponent, [], null, null, iframeMixins),
  48. (route) => {
  49. routes.push({ ...route, children: null });
  50. }
  51. );
  52. return {
  53. path: LAYOUT_PATH,
  54. component: EleLayout,
  55. redirect: HOME_PATH ?? homePath,
  56. children: routes
  57. };
  58. }
  59. /**
  60. * 获取路由组件
  61. * @param component 组件名称
  62. */
  63. function getComponent(component) {
  64. if (component) {
  65. return () => import('@/views/' + component);
  66. }
  67. }