index.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
  2. import type { App } from 'vue'
  3. // module routers
  4. import { getModuleRoutes, getModuleViewComponents } from './constantRoutes'
  5. const moduleRoutes = getModuleRoutes()
  6. getModuleViewComponents()
  7. export const constantRoutes: RouteRecordRaw[] = [
  8. {
  9. path: '/dashboard',
  10. component: () => import('/admin/layout/index.vue'),
  11. children: [
  12. {
  13. path: '',
  14. name: 'Dashboard',
  15. meta: { title: 'Dashboard', icon: 'home', hidden: false },
  16. component: () => import('/admin/views/dashboard/index.vue'),
  17. },
  18. ],
  19. },
  20. ]
  21. // @ts-ignore
  22. .concat(moduleRoutes)
  23. // default routes, it will not change to menus
  24. const defaultRoutes: RouteRecordRaw[] = [
  25. {
  26. path: '/',
  27. name: '/',
  28. component: () => import('/admin/layout/index.vue'),
  29. redirect: '/dashboard',
  30. children: [
  31. {
  32. path: '/404',
  33. name: '404',
  34. meta: { title: '404' },
  35. component: () => import('/admin/components/404/index.vue'),
  36. },
  37. ],
  38. },
  39. {
  40. path: '/login',
  41. name: 'login',
  42. meta: { title: '登录' },
  43. component: () => import('/admin/views/login/index.vue'),
  44. }
  45. ]
  46. const routes = constantRoutes.concat(defaultRoutes)
  47. const router = createRouter({
  48. history: createWebHashHistory(),
  49. routes,
  50. // 路由滚动
  51. scrollBehavior(to, from, savedPosition) {
  52. return savedPosition || { top: 0, behavior: 'smooth' }
  53. },
  54. })
  55. export function bootstrapRouter(app: App) {
  56. app.use(router)
  57. }
  58. export default router