index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 memberRouter from '@/router/modules/member'
  8. import configRouter from '@/router/modules/config'
  9. /**
  10. * Note: sub-menu only appear when route children.length >= 1
  11. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  12. *
  13. * hidden: true if set true, item will not show in the sidebar(default is false)
  14. * alwaysShow: true if set true, will always show the root menu
  15. * if not set alwaysShow, when item has more than one children route,
  16. * it will becomes nested mode, otherwise not show the root menu
  17. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  18. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  19. * meta : {
  20. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  21. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  22. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  23. noCache: true if set true, the page will no be cached(default is false)
  24. affix: true if set true, the tag will affix in the tags-view
  25. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  26. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  27. }
  28. */
  29. /**
  30. * constantRoutes
  31. * a base page that does not have permission requirements
  32. * all roles can be accessed
  33. */
  34. export const constantRoutes = [
  35. {
  36. path: '/redirect',
  37. component: Layout,
  38. hidden: true,
  39. children: [
  40. {
  41. path: '/redirect/:path(.*)',
  42. component: () => import('@/views/redirect/index')
  43. }
  44. ]
  45. },
  46. {
  47. path: '/admin',
  48. component: Layout,
  49. hidden: true,
  50. children: [
  51. {
  52. path: '/admin/role',
  53. component: () => import('@/views/admin/role') // 管理员角色列表
  54. },
  55. {
  56. path: '/admin/role-add',
  57. component: () => import('@/views/admin/role-add') // 添加角色
  58. },
  59. {
  60. path: '/admin/role-edit/:id',
  61. name: 'admin_role-edit',
  62. component: () => import('@/views/admin/role-add') // 编辑角色
  63. },
  64. {
  65. path: '/admin/role-permission/:id',
  66. name: 'admin_role-permission',
  67. component: () => import('@/views/admin/role-permission') // 角色权限
  68. },
  69. {
  70. path: '/admin/change-password',
  71. name: 'admin_change-password',
  72. component: () => import('@/views/admin/edit') // 重置密码
  73. },
  74. {
  75. path: '/admin/index',
  76. name: 'admin_index',
  77. component: () => import('@/views/admin/index') // 管理员列表
  78. },
  79. {
  80. path: '/admin/add',
  81. name: 'admin_add',
  82. component: () => import('@/views/admin/edit') // 添加管理员
  83. },
  84. {
  85. path: '/admin/edit/:id',
  86. name: 'admin_edit',
  87. component: () => import('@/views/admin/edit') // 编辑管理员
  88. }
  89. ]
  90. },
  91. {
  92. path: '/login',
  93. component: () => import('@/views/login/index'),
  94. hidden: true
  95. },
  96. {
  97. path: '/auth-redirect',
  98. component: () => import('@/views/login/auth-redirect'),
  99. hidden: true
  100. },
  101. {
  102. path: '/404',
  103. component: () => import('@/views/error-page/404'),
  104. hidden: true
  105. },
  106. {
  107. path: '/401',
  108. component: () => import('@/views/error-page/401'),
  109. hidden: true
  110. },
  111. {
  112. path: '/',
  113. component: Layout,
  114. redirect: '/dashboard',
  115. children: [
  116. {
  117. path: 'dashboard',
  118. component: () => import('@/views/dashboard/index'),
  119. name: 'Dashboard',
  120. meta: { title: 'dashboard', icon: 'dashboard', affix: true }
  121. }
  122. ]
  123. },
  124. {
  125. path: '/profile',
  126. component: Layout,
  127. redirect: '/profile/index',
  128. hidden: true,
  129. children: [
  130. {
  131. path: 'index',
  132. component: () => import('@/views/profile/index'),
  133. name: 'Profile',
  134. meta: { title: 'profile', icon: 'user', noCache: true }
  135. }
  136. ]
  137. }
  138. ]
  139. /**
  140. * asyncRoutes
  141. * the routes that need to be dynamically loaded based on user roles
  142. */
  143. export const asyncRoutes = [
  144. /** when your routing map is too long, you can split it into small modules **/
  145. // 会员
  146. memberRouter,
  147. // 设置
  148. configRouter,
  149. {
  150. path: '/error',
  151. component: Layout,
  152. redirect: 'noRedirect',
  153. name: 'ErrorPages',
  154. meta: {
  155. title: 'errorPages',
  156. icon: '404'
  157. },
  158. children: [
  159. {
  160. path: '401',
  161. component: () => import('@/views/error-page/401'),
  162. name: 'Page401',
  163. meta: { title: 'page401', noCache: true }
  164. },
  165. {
  166. path: '404',
  167. component: () => import('@/views/error-page/404'),
  168. name: 'Page404',
  169. meta: { title: 'page404', noCache: true }
  170. }
  171. ]
  172. },
  173. {
  174. path: '/error-log',
  175. component: Layout,
  176. children: [
  177. {
  178. path: 'log',
  179. component: () => import('@/views/error-log/index'),
  180. name: 'ErrorLog',
  181. meta: { title: 'errorLog', icon: 'bug' }
  182. }
  183. ]
  184. },
  185. // 404 page must be placed at the end !!!
  186. { path: '*', redirect: '/404', hidden: true }
  187. ]
  188. const createRouter = () => new Router({
  189. // mode: 'history', // require service support
  190. scrollBehavior: () => ({ y: 0 }),
  191. routes: constantRoutes.concat(asyncRoutes)
  192. })
  193. const router = createRouter()
  194. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  195. export function resetRouter() {
  196. const newRouter = createRouter()
  197. router.matcher = newRouter.matcher // reset router
  198. }
  199. export function selfAddRoutes(params) {
  200. const newRouter = createRouter()
  201. router.matcher = newRouter.matcher
  202. router.addRoutes(params)
  203. }
  204. export default router