index.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
  2. export const Layout = () => import("@/layout/index.vue");
  3. // 静态路由
  4. export const constantRoutes: RouteRecordRaw[] = [
  5. {
  6. path: "/redirect",
  7. component: Layout,
  8. meta: { hidden: true },
  9. children: [
  10. {
  11. path: "/redirect/:path(.*)",
  12. component: () => import("@/views/redirect/index.vue"),
  13. },
  14. ],
  15. },
  16. {
  17. path: "/login",
  18. component: () => import("@/views/login/index.vue"),
  19. meta: { hidden: true },
  20. },
  21. // {
  22. // path: "/",
  23. // name: "/",
  24. // component: Layout,
  25. // redirect: "/dashboard",
  26. // children: [
  27. // {
  28. // path: "dashboard",
  29. // component: () => import("@/views/dashboard/index.vue"),
  30. // name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
  31. // // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
  32. // meta: {
  33. // title: "dashboard",
  34. // icon: "homepage",
  35. // affix: true,
  36. // keepAlive: true,
  37. // alwaysShow: false,
  38. // },
  39. // },
  40. // {
  41. // path: "401",
  42. // component: () => import("@/views/error-page/401.vue"),
  43. // meta: { hidden: true },
  44. // },
  45. // {
  46. // path: "404",
  47. // component: () => import("@/views/error-page/404.vue"),
  48. // meta: { hidden: true },
  49. // },
  50. // ],
  51. // },
  52. {
  53. path: "/:pathMatch(.*)*", // 必备
  54. component: () => import("@/views/error-page/404.vue"),
  55. },
  56. // 外部链接
  57. // {
  58. // path: "/external-link",
  59. // component: Layout,
  60. // children: [ {
  61. // component: () => import("@/views/external-link/index.vue"),
  62. // path: "https://www.cnblogs.com/haoxianrui/",
  63. // meta: { title: "外部链接", icon: "link" },
  64. // },
  65. // ],
  66. // },
  67. // 多级嵌套路由
  68. /* {
  69. path: '/nested',
  70. component: Layout,
  71. redirect: '/nested/level1/level2',
  72. name: 'Nested',
  73. meta: {title: '多级菜单', icon: 'nested'},
  74. children: [
  75. {
  76. path: 'level1',
  77. component: () => import('@/views/nested/level1/index.vue'),
  78. name: 'Level1',
  79. meta: {title: '菜单一级'},
  80. redirect: '/nested/level1/level2',
  81. children: [
  82. {
  83. path: 'level2',
  84. component: () => import('@/views/nested/level1/level2/index.vue'),
  85. name: 'Level2',
  86. meta: {title: '菜单二级'},
  87. redirect: '/nested/level1/level2/level3',
  88. children: [
  89. {
  90. path: 'level3-1',
  91. component: () => import('@/views/nested/level1/level2/level3/index1.vue'),
  92. name: 'Level3-1',
  93. meta: {title: '菜单三级-1'}
  94. },
  95. {
  96. path: 'level3-2',
  97. component: () => import('@/views/nested/level1/level2/level3/index2.vue'),
  98. name: 'Level3-2',
  99. meta: {title: '菜单三级-2'}
  100. }
  101. ]
  102. }
  103. ]
  104. },
  105. ]
  106. }*/
  107. ];
  108. /**
  109. * 创建路由
  110. */
  111. const router = createRouter({
  112. history: createWebHashHistory(),
  113. routes: constantRoutes,
  114. // 刷新时,滚动条位置还原
  115. scrollBehavior: () => ({ left: 0, top: 0 }),
  116. });
  117. /**
  118. * 重置路由
  119. */
  120. export function resetRouter() {
  121. router.replace({ path: "/login" });
  122. }
  123. export default router;