index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // 静态路由
  8. export const constantRoutes = [
  9. {
  10. path: '/redirect',
  11. component: Layout,
  12. meta: { hidden: true },
  13. children: [
  14. {
  15. path: '/redirect/:path(.*)',
  16. component: () => import('@/views/redirect/index.vue')
  17. }
  18. ]
  19. },
  20. {
  21. path: '/login',
  22. name: 'Login',
  23. meta: { title: '系统登录' },
  24. component: () => import('@/views/login/index.vue')
  25. },
  26. {
  27. path: '/',
  28. name: 'Layout',
  29. component: Layout,
  30. children: [
  31. ...systemRoutes,
  32. ...userRoutes,
  33. {
  34. path: '/',
  35. name: 'home',
  36. meta: {
  37. title: '首页',
  38. affix: true,
  39. keepAlive: true,
  40. alwaysShow: false
  41. },
  42. component: () => import('@/views/home/index.vue')
  43. },
  44. {
  45. path: '401',
  46. component: () => import('@/views/error-page/401.vue'),
  47. meta: { hidden: true }
  48. },
  49. {
  50. path: '404',
  51. component: () => import('@/views/error-page/404.vue'),
  52. meta: { hidden: true }
  53. },
  54. {
  55. path: '/acccount',
  56. name: 'acccount',
  57. meta: {
  58. title: '账号管理',
  59. affix: true,
  60. keepAlive: true,
  61. alwaysShow: false
  62. },
  63. component: () => import('@/views/account/index.vue')
  64. }
  65. ]
  66. }
  67. ]
  68. /**
  69. * 创建路由
  70. */
  71. const router = createRouter({
  72. history: createWebHistory(),
  73. routes: constantRoutes,
  74. // 刷新时,滚动条位置还原
  75. scrollBehavior: () => ({ left: 0, top: 0 })
  76. })
  77. registerBeforeRouter(router)
  78. registerAfterRouter(router)
  79. export default router