index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. {
  46. path: 'dashboard',
  47. name: 'Dashboard',
  48. component: () => import('@/views/dashboard/index'),
  49. meta: {
  50. title: 'Dashboard',
  51. icon: 'dashboard'
  52. }
  53. }
  54. ]
  55. },
  56. {
  57. path: '/example',
  58. component: Layout,
  59. redirect: '/example/table',
  60. name: 'Example',
  61. meta: {
  62. title: 'Example',
  63. icon: 'el-icon-s-help'
  64. },
  65. children: [
  66. {
  67. path: 'table',
  68. name: 'Table',
  69. component: () => import('@/views/table/index'),
  70. meta: {
  71. title: 'Table',
  72. icon: 'table'
  73. }
  74. },
  75. {
  76. path: 'tree',
  77. name: 'Tree',
  78. component: () => import('@/views/tree/index'),
  79. meta: {
  80. title: 'Tree',
  81. icon: 'tree'
  82. }
  83. }
  84. ]
  85. },
  86. {
  87. path: '/form',
  88. component: Layout,
  89. children: [
  90. {
  91. path: 'index',
  92. name: 'Form',
  93. component: () => import('@/views/form/index'),
  94. meta: {
  95. title: 'Form',
  96. icon: 'form'
  97. }
  98. }
  99. ]
  100. },
  101. // 404 page must be placed at the end !!!
  102. {
  103. path: '*',
  104. redirect: '/404',
  105. hidden: true
  106. }
  107. ];
  108. /**
  109. * asyncRoutes
  110. * the routes that need to be dynamically loaded based on user roles
  111. */
  112. export const asyncRoutes = [
  113. {
  114. path: '/nested',
  115. component: Layout,
  116. redirect: '/nested/menu1',
  117. name: 'Nested',
  118. meta: {
  119. title: 'Nested',
  120. icon: 'nested'
  121. },
  122. children: [
  123. {
  124. path: 'menu1',
  125. component: () => import('@/views/nested/menu1/index'), // Parent router-view
  126. name: 'Menu1',
  127. meta: {
  128. title: 'Menu1'
  129. },
  130. children: [
  131. {
  132. path: 'menu1-1',
  133. component: () => import('@/views/nested/menu1/menu1-1'),
  134. name: 'Menu1-1',
  135. meta: {
  136. title: 'Menu1-1'
  137. }
  138. },
  139. {
  140. path: 'menu1-2',
  141. component: () => import('@/views/nested/menu1/menu1-2'),
  142. name: 'Menu1-2',
  143. meta: {
  144. title: 'Menu1-2'
  145. },
  146. children: [
  147. {
  148. path: 'menu1-2-1',
  149. component: () =>
  150. import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  151. name: 'Menu1-2-1',
  152. meta: {
  153. title: 'Menu1-2-1'
  154. }
  155. },
  156. {
  157. path: 'menu1-2-2',
  158. component: () =>
  159. import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  160. name: 'Menu1-2-2',
  161. meta: {
  162. title: 'Menu1-2-2'
  163. }
  164. }
  165. ]
  166. },
  167. {
  168. path: 'menu1-3',
  169. component: () => import('@/views/nested/menu1/menu1-3'),
  170. name: 'Menu1-3',
  171. meta: {
  172. title: 'Menu1-3'
  173. }
  174. }
  175. ]
  176. },
  177. {
  178. path: 'menu2',
  179. component: () => import('@/views/nested/menu2/index'),
  180. name: 'Menu2',
  181. meta: {
  182. title: 'menu2'
  183. }
  184. }
  185. ]
  186. },
  187. {
  188. path: 'external-link',
  189. component: Layout,
  190. children: [
  191. {
  192. path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  193. meta: {
  194. title: 'External Link',
  195. icon: 'link'
  196. }
  197. }
  198. ]
  199. }
  200. ];
  201. const createRouter = () =>
  202. new Router({
  203. // mode: 'history', // require service support
  204. scrollBehavior: () => ({
  205. y: 0
  206. }),
  207. routes: constantRoutes
  208. });
  209. const router = createRouter();
  210. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  211. export function resetRouter() {
  212. const newRouter = createRouter();
  213. router.matcher = newRouter.matcher; // reset router
  214. }
  215. export default router;