index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. /**
  7. * Note: sub-menu only appear when route children.length >= 1
  8. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  9. *
  10. * hidden: true if set true, item will not show in the sidebar(default is false)
  11. * alwaysShow: true if set true, will always show the root menu
  12. * if not set alwaysShow, when item has more than one children route,
  13. * it will becomes nested mode, otherwise not show the root menu
  14. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  15. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  16. * meta : {
  17. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  18. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  19. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  20. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  21. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  22. }
  23. */
  24. /**
  25. * constantRoutes
  26. * a base page that does not have permission requirements
  27. * all roles can be accessed
  28. */
  29. export const constantRoutes = [
  30. {
  31. path: '/login',
  32. component: () => import('@/views/login/index'),
  33. hidden: true
  34. },
  35. {
  36. path: '/404',
  37. component: () => import('@/views/404'),
  38. hidden: true
  39. },
  40. {
  41. path: '/',
  42. component: Layout,
  43. redirect: '/dashboard',
  44. children: [{
  45. path: 'dashboard',
  46. name: 'Dashboard',
  47. component: () => import('@/views/dashboard/index'),
  48. meta: { title: 'Dashboard', icon: 'dashboard' }
  49. }]
  50. },
  51. {
  52. path: '/example',
  53. component: Layout,
  54. redirect: '/example/table',
  55. name: 'Example',
  56. meta: { title: 'Example', icon: 'el-icon-s-help' },
  57. children: [
  58. {
  59. path: 'table',
  60. name: 'Table',
  61. component: () => import('@/views/table/index'),
  62. meta: { title: 'Table', icon: 'table' }
  63. },
  64. {
  65. path: 'tree',
  66. name: 'Tree',
  67. component: () => import('@/views/tree/index'),
  68. meta: { title: 'Tree', icon: 'tree' }
  69. }
  70. ]
  71. },
  72. {
  73. path: '/form',
  74. component: Layout,
  75. children: [
  76. {
  77. path: 'index',
  78. name: 'Form',
  79. component: () => import('@/views/form/index'),
  80. meta: { title: 'Form', icon: 'form' }
  81. }
  82. ]
  83. },
  84. {
  85. path: '/level',
  86. component: Layout,
  87. meta: { title: 'Level', icon: 'level' },
  88. children: [
  89. {
  90. path: 'levelList',
  91. name: 'levelList',
  92. component: () => import('@/views/level/levelList'),
  93. meta: { title: '等级列表', icon: 'level' }
  94. },{
  95. path: 'addLevel',
  96. name: 'addLevel',
  97. component: () => import('@/views/level/addLevel'),
  98. meta: { title: '添加等级', icon: 'level' }
  99. }
  100. ]
  101. },
  102. {
  103. path: '/location',
  104. component: Layout,
  105. meta: { title: 'Location', icon: 'location' },
  106. children: [
  107. {
  108. path: 'locationList',
  109. name: 'locationList',
  110. component: () => import('@/views/location/locationList'),
  111. meta: { title: '地址列表', icon: 'location' }
  112. },{
  113. path: 'addLocation',
  114. name: 'addLocation',
  115. component: () => import('@/views/location/addLocation'),
  116. meta: { title: '添加地址', icon: 'location' }
  117. }
  118. ]
  119. },
  120. {
  121. path: '/nested',
  122. component: Layout,
  123. redirect: '/nested/menu1',
  124. name: 'Nested',
  125. meta: {
  126. title: 'Nested',
  127. icon: 'nested'
  128. },
  129. children: [
  130. {
  131. path: 'menu1',
  132. component: () => import('@/views/nested/menu1/index'), // Parent router-view
  133. name: 'Menu1',
  134. meta: { title: 'Menu1' },
  135. children: [
  136. {
  137. path: 'menu1-1',
  138. component: () => import('@/views/nested/menu1/menu1-1'),
  139. name: 'Menu1-1',
  140. meta: { title: 'Menu1-1' }
  141. },
  142. {
  143. path: 'menu1-2',
  144. component: () => import('@/views/nested/menu1/menu1-2'),
  145. name: 'Menu1-2',
  146. meta: { title: 'Menu1-2' },
  147. children: [
  148. {
  149. path: 'menu1-2-1',
  150. component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  151. name: 'Menu1-2-1',
  152. meta: { title: 'Menu1-2-1' }
  153. },
  154. {
  155. path: 'menu1-2-2',
  156. component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  157. name: 'Menu1-2-2',
  158. meta: { title: 'Menu1-2-2' }
  159. }
  160. ]
  161. },
  162. {
  163. path: 'menu1-3',
  164. component: () => import('@/views/nested/menu1/menu1-3'),
  165. name: 'Menu1-3',
  166. meta: { title: 'Menu1-3' }
  167. }
  168. ]
  169. },
  170. {
  171. path: 'menu2',
  172. component: () => import('@/views/nested/menu2/index'),
  173. name: 'Menu2',
  174. meta: { title: 'menu2' }
  175. }
  176. ]
  177. },
  178. {
  179. path: 'external-link',
  180. component: Layout,
  181. children: [
  182. {
  183. path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  184. meta: { title: 'External Link', icon: 'link' }
  185. }
  186. ]
  187. },
  188. // 404 page must be placed at the end !!!
  189. { path: '*', redirect: '/404', hidden: true }
  190. ]
  191. const createRouter = () => new Router({
  192. // mode: 'history', // require service support
  193. scrollBehavior: () => ({ y: 0 }),
  194. routes: constantRoutes
  195. })
  196. const router = createRouter()
  197. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  198. export function resetRouter() {
  199. const newRouter = createRouter()
  200. router.matcher = newRouter.matcher // reset router
  201. }
  202. export default router