index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. /* Router Modules */
  7. import clubRouter from './modules/club'
  8. import goodsRouter from './modules/goods'
  9. import orderRouter from './modules/order'
  10. import financeRouter from './modules/finance'
  11. import otherRouter from './modules/other'
  12. /**
  13. * Note: sub-menu only appear when route children.length >= 1
  14. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  15. *
  16. * hidden: true if set true, item will not show in the sidebar(default is false)
  17. * alwaysShow: true if set true, will always show the root menu
  18. * if not set alwaysShow, when item has more than one children route,
  19. * it will becomes nested mode, otherwise not show the root menu
  20. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  21. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  22. * meta : {
  23. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  24. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  25. icon: 'svg-name' the icon show in the sidebar
  26. noCache: true if set true, the page will no be cached(default is false)
  27. affix: true if set true, the tag will affix in the tags-view
  28. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  29. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  30. }
  31. */
  32. /**
  33. * constantRoutes
  34. * a base page that does not have permission requirements
  35. * all roles can be accessed
  36. */
  37. export const constantRoutes = [
  38. {
  39. path: '/redirect',
  40. component: Layout,
  41. hidden: true,
  42. children: [
  43. {
  44. path: '/redirect/:path*',
  45. component: () => import('@/views/redirect/index')
  46. }
  47. ]
  48. },
  49. {
  50. path: '/login',
  51. component: () => import('@/views/login/index'),
  52. hidden: true
  53. },
  54. {
  55. path: '/auth-redirect',
  56. component: () => import('@/views/login/auth-redirect'),
  57. hidden: true
  58. },
  59. {
  60. path: '/404',
  61. component: () => import('@/views/error-page/404'),
  62. hidden: true
  63. },
  64. {
  65. path: '/401',
  66. component: () => import('@/views/error-page/401'),
  67. hidden: true
  68. },
  69. {
  70. path: '/',
  71. component: Layout,
  72. redirect: '/dashboard',
  73. children: [
  74. {
  75. path: 'dashboard',
  76. component: () => import('@/views/dashboard/index'),
  77. name: 'Dashboard',
  78. meta: { title: '首页', icon: 'ma-home', noCache: true, affix: true }
  79. }
  80. ]
  81. }
  82. ]
  83. /**
  84. * asyncRoutes
  85. * the routes that need to be dynamically loaded based on user roles
  86. */
  87. export const asyncRoutes = [
  88. clubRouter,
  89. goodsRouter,
  90. orderRouter,
  91. financeRouter,
  92. otherRouter,
  93. // 404 page must be placed at the end !!!
  94. { path: '*', redirect: '/404', hidden: true }
  95. ]
  96. const createRouter = () => new Router({
  97. // mode: 'history', // require service support
  98. scrollBehavior: () => ({ y: 0 }),
  99. routes: constantRoutes
  100. })
  101. const router = createRouter()
  102. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  103. export function resetRouter() {
  104. const newRouter = createRouter()
  105. router.matcher = newRouter.matcher // reset router
  106. }
  107. export default router