index.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {
  2. createRouter,
  3. createWebHistory,
  4. RouteRecordRaw,
  5. createWebHashHistory,
  6. Router,
  7. } from 'vue-router'
  8. import Layout from '@/layout/index.vue'
  9. // 扩展继承属性
  10. interface extendRoute {
  11. hidden?: boolean
  12. }
  13. //
  14. import systemRouter from './modules/system'
  15. // 异步组件
  16. export const asyncRoutes = [...systemRouter]
  17. /**
  18. * path ==> 路由路径
  19. * name ==> 路由名称
  20. * component ==> 路由组件
  21. * redirect ==> 路由重定向
  22. * alwaysShow ==> 如果设置为true,将始终显示根菜单,无论其子路由长度如何
  23. * hidden ==> 如果“hidden:true”不会显示在侧边栏中(默认值为false)
  24. * keepAlive ==> 设为true 缓存
  25. * meta ==> 路由元信息
  26. * meta.title ==> 路由标题
  27. * meta.icon ==> 菜单icon
  28. * meta.affix ==> 如果设置为true将会出现在 标签栏中
  29. * meta.breadcrumb ==> 如果设置为false,该项将隐藏在breadcrumb中(默认值为true)
  30. * meta.activeMenu ==> 详情页的时候可以设置菜单高亮 ,高亮菜单的path
  31. */
  32. export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  33. {
  34. path: '/404',
  35. name: '404',
  36. component: () => import('@/views/errorPages/404.vue'),
  37. hidden: true,
  38. },
  39. {
  40. path: '/403',
  41. name: '403',
  42. component: () => import('@/views/errorPages/403.vue'),
  43. hidden: true,
  44. },
  45. {
  46. path: '/login',
  47. name: 'login',
  48. component: () => import('@/views/login/User.vue'),
  49. hidden: true,
  50. redirect: '/signin',
  51. children: [
  52. {
  53. path: '/signin',
  54. name: 'SignIn',
  55. component: () => import('@/views/login/index.vue'),
  56. hidden: true,
  57. },
  58. {
  59. path: '/forget',
  60. name: 'Forget',
  61. component: () => import('@/views/login/Forget.vue'),
  62. hidden: true,
  63. },
  64. ],
  65. },
  66. {
  67. path: '/',
  68. name: 'layout',
  69. component: Layout,
  70. redirect: '/home',
  71. meta: { title: '首页', icon: 'House' },
  72. children: [
  73. {
  74. path: '/home',
  75. component: () => import('@/views/home/index.vue'),
  76. name: 'home',
  77. meta: { title: '首页', icon: 'House', affix: true, role: ['other'] },
  78. },
  79. ],
  80. },
  81. ]
  82. /**
  83. * notFoundRouter(找不到路由)
  84. */
  85. export const notFoundRouter = {
  86. path: '/:pathMatch(.*)',
  87. name: 'notFound',
  88. redirect: '/404',
  89. }
  90. const router = createRouter({
  91. // history: createWebHistory(process.env.BASE_URL), // history
  92. history: createWebHashHistory(), // hash
  93. routes: constantRoutes,
  94. })
  95. export default router