index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. path: '/login',
  31. component: () => import('@/views/login/index'),
  32. hidden: true
  33. },
  34. {
  35. path: '/404',
  36. component: () => import('@/views/404'),
  37. hidden: true
  38. },
  39. {
  40. path: '/',
  41. component: Layout,
  42. redirect: '/dashboard',
  43. children: [{
  44. path: 'dashboard',
  45. name: 'Dashboard',
  46. component: () => import('@/views/dashboard/index'),
  47. meta: {
  48. title: 'Dashboard',
  49. icon: 'dashboard'
  50. }
  51. }]
  52. },
  53. {
  54. path: '/example',
  55. component: Layout,
  56. redirect: '/example/table',
  57. name: 'Example',
  58. meta: {
  59. title: 'Example',
  60. icon: 'el-icon-s-help'
  61. },
  62. children: [{
  63. path: 'table',
  64. name: 'Table',
  65. component: () => import('@/views/table/index'),
  66. meta: {
  67. title: 'Table',
  68. icon: 'table'
  69. }
  70. },
  71. {
  72. path: 'tree',
  73. name: 'Tree',
  74. component: () => import('@/views/tree/index'),
  75. meta: {
  76. title: 'Tree',
  77. icon: 'tree'
  78. }
  79. }
  80. ]
  81. },
  82. {
  83. path: '/level',
  84. component: Layout,
  85. name: 'Level',
  86. meta: {
  87. title: '等级',
  88. icon: 'level'
  89. },
  90. children: [{
  91. path: 'levelList',
  92. name: 'levelList',
  93. component: () => import('@/views/level/levelList.vue'),
  94. meta: {
  95. title: '等级列表',
  96. icon: 'level'
  97. }
  98. },
  99. {
  100. path: 'addLevel',
  101. name: 'addLevel',
  102. component: () => import('@/views/level/addLevel.vue'),
  103. meta: {
  104. title: '添加等级',
  105. icon: 'level'
  106. }
  107. }
  108. ]
  109. },
  110. {
  111. path: '/location',
  112. component: Layout,
  113. name: 'Location',
  114. meta: {
  115. title: '地址',
  116. icon: 'location'
  117. },
  118. children: [{
  119. path: 'locationList',
  120. name: 'locationList',
  121. component: () => import('@/views/location/locationList.vue'),
  122. meta: {
  123. title: '地址列表',
  124. icon: 'location'
  125. }
  126. },
  127. {
  128. path: 'addLocation',
  129. name: 'addLocation',
  130. component: () => import('@/views/location/addLocation.vue'),
  131. meta: {
  132. title: '添加地址',
  133. icon: 'location'
  134. }
  135. }
  136. ]
  137. },
  138. {
  139. path: '/message',
  140. component: Layout,
  141. name: 'Message',
  142. meta: {
  143. title: '信息',
  144. icon: 'message'
  145. },
  146. children: [{
  147. path: 'messageList',
  148. name: 'messageList',
  149. component: () => import('@/views/message/messageList.vue'),
  150. meta: {
  151. title: '信息列表',
  152. icon: 'message'
  153. }
  154. },
  155. {
  156. path: 'addMessage',
  157. name: 'addMessage',
  158. component: () => import('@/views/message/addMessage.vue'),
  159. meta: {
  160. title: '添加信息',
  161. icon: 'message'
  162. }
  163. }
  164. ]
  165. },
  166. {
  167. path: '/form',
  168. component: Layout,
  169. children: [{
  170. path: 'index',
  171. name: 'Form',
  172. component: () => import('@/views/form/index'),
  173. meta: {
  174. title: 'Form',
  175. icon: 'form'
  176. }
  177. }]
  178. },
  179. {
  180. path: '/nested',
  181. component: Layout,
  182. redirect: '/nested/menu1',
  183. name: 'Nested',
  184. meta: {
  185. title: 'Nested',
  186. icon: 'nested'
  187. },
  188. children: [{
  189. path: 'menu1',
  190. component: () => import('@/views/nested/menu1/index'), // Parent router-view
  191. name: 'Menu1',
  192. meta: {
  193. title: 'Menu1'
  194. },
  195. children: [{
  196. path: 'menu1-1',
  197. component: () => import('@/views/nested/menu1/menu1-1'),
  198. name: 'Menu1-1',
  199. meta: {
  200. title: 'Menu1-1'
  201. }
  202. },
  203. {
  204. path: 'menu1-2',
  205. component: () => import('@/views/nested/menu1/menu1-2'),
  206. name: 'Menu1-2',
  207. meta: {
  208. title: 'Menu1-2'
  209. },
  210. children: [{
  211. path: 'menu1-2-1',
  212. component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  213. name: 'Menu1-2-1',
  214. meta: {
  215. title: 'Menu1-2-1'
  216. }
  217. },
  218. {
  219. path: 'menu1-2-2',
  220. component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  221. name: 'Menu1-2-2',
  222. meta: {
  223. title: 'Menu1-2-2'
  224. }
  225. }
  226. ]
  227. },
  228. {
  229. path: 'menu1-3',
  230. component: () => import('@/views/nested/menu1/menu1-3'),
  231. name: 'Menu1-3',
  232. meta: {
  233. title: 'Menu1-3'
  234. }
  235. }
  236. ]
  237. },
  238. {
  239. path: 'menu2',
  240. component: () => import('@/views/nested/menu2/index'),
  241. name: 'Menu2',
  242. meta: {
  243. title: 'menu2'
  244. }
  245. }
  246. ]
  247. },
  248. {
  249. path: 'external-link',
  250. component: Layout,
  251. children: [{
  252. path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  253. meta: {
  254. title: 'External Link',
  255. icon: 'link'
  256. }
  257. }]
  258. },
  259. // 404 page must be placed at the end !!!
  260. {
  261. path: '*',
  262. redirect: '/404',
  263. hidden: true
  264. }
  265. ]
  266. const createRouter = () => new Router({
  267. // mode: 'history', // require service support
  268. scrollBehavior: () => ({
  269. y: 0
  270. }),
  271. routes: constantRoutes
  272. })
  273. const router = createRouter()
  274. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  275. export function resetRouter() {
  276. const newRouter = createRouter()
  277. router.matcher = newRouter.matcher // reset router
  278. }
  279. export default router