index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import { registerBeforeRouter, registerAfterRouter } from './guard'
  3. export const homeIndex = () => import('@/views/home/index.vue')
  4. export const Layout = () => import('@/layout/index.vue')
  5. import { routes as systemRoutes } from './modules/system'
  6. import { routes as userRoutes } from './modules/user'
  7. import { routes as jobRoutes } from './modules/job'
  8. import { routes as colonyRoutes } from './modules/colony'
  9. import { routes as controlRoutes } from './modules/control'
  10. // 静态路由
  11. export const constantRoutes = [
  12. {
  13. path: '/redirect',
  14. component: Layout,
  15. meta: { hidden: true },
  16. children: [
  17. {
  18. path: '/redirect/:path(.*)',
  19. component: () => import('@/views/redirect/index.vue')
  20. }
  21. ]
  22. },
  23. {
  24. path: '/login',
  25. name: 'Login',
  26. meta: { title: '系统登录' },
  27. component: () => import('@/views/login/index.vue')
  28. },
  29. {
  30. path: '/',
  31. name: 'Layout',
  32. component: Layout,
  33. children: [
  34. {
  35. path: '/',
  36. name: 'home',
  37. meta: {
  38. title: '首页',
  39. affix: true,
  40. keepAlive: true,
  41. alwaysShow: false
  42. },
  43. component: () => import('@/views/home/index.vue')
  44. },
  45. ...systemRoutes,
  46. ...userRoutes,
  47. ...jobRoutes,
  48. ...colonyRoutes,
  49. ...controlRoutes,
  50. {
  51. path: '/operate',
  52. name: 'operate',
  53. meta: { title: '操作日志' },
  54. component: () => import('@/views/operate/index.vue')
  55. },
  56. {
  57. path: '/acccount',
  58. name: 'acccount',
  59. meta: { title: '修改密码' },
  60. component: () => import('@/views/account/index.vue')
  61. }
  62. ]
  63. },
  64. {
  65. path: '/401',
  66. name: '401',
  67. component: () => import('@/views/error-page/401.vue'),
  68. meta: { hidden: true }
  69. },
  70. {
  71. path: '/404',
  72. name: '404',
  73. component: () => import('@/views/error-page/404.vue'),
  74. meta: { hidden: true }
  75. }
  76. ]
  77. /**
  78. * 创建路由
  79. */
  80. const router = createRouter({
  81. history: createWebHistory(),
  82. routes: constantRoutes,
  83. // 刷新时,滚动条位置还原
  84. scrollBehavior: () => ({ left: 0, top: 0 })
  85. })
  86. registerBeforeRouter(router)
  87. registerAfterRouter(router)
  88. export default router