index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 componentsRouter from './modules/components'
  8. import chartsRouter from './modules/charts'
  9. import tableRouter from './modules/table'
  10. import nestedRouter from './modules/nested'
  11. /**
  12. * Note: sub-menu only appear when route children.length >= 1
  13. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  14. *
  15. * hidden: true if set true, item will not show in the sidebar(default is false)
  16. * alwaysShow: true if set true, will always show the root menu
  17. * if not set alwaysShow, when item has more than one children route,
  18. * it will becomes nested mode, otherwise not show the root menu
  19. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  20. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  21. * meta : {
  22. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  23. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  24. icon: 'svg-name' the icon show in the sidebar
  25. noCache: true if set true, the page will no be cached(default is false)
  26. affix: true if set true, the tag will affix in the tags-view
  27. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  28. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  29. }
  30. */
  31. /**
  32. * constantRoutes
  33. * a base page that does not have permission requirements
  34. * all roles can be accessed
  35. */
  36. export const constantRoutes = [
  37. {
  38. path: '/login',
  39. component: () => import('@/views/login/index'),
  40. hidden: true
  41. },
  42. {
  43. path: '/auth-redirect',
  44. component: () => import('@/views/login/auth-redirect'),
  45. hidden: true
  46. },
  47. {
  48. path: '/404',
  49. component: () => import('@/views/error-page/404'),
  50. hidden: true
  51. },
  52. {
  53. path: '/401',
  54. component: () => import('@/views/error-page/401'),
  55. hidden: true
  56. },
  57. {
  58. path: '/',
  59. component: Layout,
  60. redirect: '/dashboard',
  61. children: [
  62. {
  63. path: 'dashboard',
  64. component: () => import('@/views/dashboard/index'),
  65. name: 'Dashboard',
  66. meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
  67. }
  68. ]
  69. },
  70. {
  71. path: '/profile',
  72. component: Layout,
  73. redirect: '/profile/index',
  74. hidden: true,
  75. children: [
  76. {
  77. path: 'index',
  78. component: () => import('@/views/profile/index'),
  79. name: 'Profile',
  80. meta: { title: 'Profile', icon: 'user', noCache: true }
  81. }
  82. ]
  83. }
  84. ]
  85. /**
  86. * asyncRoutes
  87. * the routes that need to be dynamically loaded based on user roles
  88. */
  89. export const asyncRoutes = [
  90. {
  91. path: '/profile',
  92. component: Layout,
  93. redirect: '/profile/index',
  94. hidden: true,
  95. children: [
  96. {
  97. path: 'index',
  98. component: () => import('@/views/profile/index'),
  99. name: 'Profile',
  100. meta: { title: 'Profile', icon: 'user', noCache: true }
  101. }
  102. ]
  103. },
  104. {
  105. path: '/permission',
  106. component: Layout,
  107. redirect: '/permission/page',
  108. alwaysShow: true, // will always show the root menu
  109. name: 'Permission',
  110. meta: {
  111. title: 'Permission',
  112. icon: 'lock',
  113. roles: ['admin', 'editor'] // you can set roles in root nav
  114. },
  115. children: [
  116. {
  117. path: 'page',
  118. component: () => import('@/views/permission/page'),
  119. name: 'PagePermission',
  120. meta: {
  121. title: 'Page Permission',
  122. roles: ['admin'] // or you can only set roles in sub nav
  123. }
  124. },
  125. {
  126. path: 'directive',
  127. component: () => import('@/views/permission/directive'),
  128. name: 'DirectivePermission',
  129. meta: {
  130. title: 'Directive Permission'
  131. // if do not set roles, means: this page does not require permission
  132. }
  133. },
  134. {
  135. path: 'role',
  136. component: () => import('@/views/permission/role'),
  137. name: 'RolePermission',
  138. meta: {
  139. title: 'Role Permission',
  140. roles: ['admin']
  141. }
  142. }
  143. ]
  144. },
  145. componentsRouter,
  146. chartsRouter,
  147. nestedRouter,
  148. tableRouter,
  149. {
  150. path: '/error',
  151. component: Layout,
  152. redirect: 'noRedirect',
  153. name: 'ErrorPages',
  154. meta: {
  155. title: 'Error Pages',
  156. icon: '404'
  157. },
  158. children: [
  159. {
  160. path: '401',
  161. component: () => import('@/views/error-page/401'),
  162. name: 'Page401',
  163. meta: { title: '401', noCache: true }
  164. },
  165. {
  166. path: '404',
  167. component: () => import('@/views/error-page/404'),
  168. name: 'Page404',
  169. meta: { title: '404', 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: 'Error Log', icon: 'bug' }
  182. }
  183. ]
  184. },
  185. {
  186. path: '/excel',
  187. component: Layout,
  188. redirect: '/excel/export-excel',
  189. name: 'Excel',
  190. meta: {
  191. title: 'Excel',
  192. icon: 'excel'
  193. },
  194. children: [
  195. {
  196. path: 'export-excel',
  197. component: () => import('@/views/excel/export-excel'),
  198. name: 'ExportExcel',
  199. meta: { title: 'Export Excel' }
  200. },
  201. {
  202. path: 'export-selected-excel',
  203. component: () => import('@/views/excel/select-excel'),
  204. name: 'SelectExcel',
  205. meta: { title: 'Export Selected' }
  206. },
  207. {
  208. path: 'export-merge-header',
  209. component: () => import('@/views/excel/merge-header'),
  210. name: 'MergeHeader',
  211. meta: { title: 'Merge Header' }
  212. },
  213. {
  214. path: 'upload-excel',
  215. component: () => import('@/views/excel/upload-excel'),
  216. name: 'UploadExcel',
  217. meta: { title: 'Upload Excel' }
  218. }
  219. ]
  220. },
  221. {
  222. path: '/theme',
  223. component: Layout,
  224. children: [
  225. {
  226. path: 'index',
  227. component: () => import('@/views/theme/index'),
  228. name: 'Theme',
  229. meta: { title: 'Theme', icon: 'theme' }
  230. }
  231. ]
  232. },
  233. {
  234. path: 'external-link',
  235. component: Layout,
  236. children: [
  237. {
  238. path: 'https://github.com/PanJiaChen/vue-element-admin',
  239. meta: { title: 'External Link', icon: 'link' }
  240. }
  241. ]
  242. },
  243. // 404 page must be placed at the end !!!
  244. { path: '*', redirect: '/404', hidden: true }
  245. ]
  246. const createRouter = () => new Router({
  247. // mode: 'history', // require service support
  248. scrollBehavior: () => ({ y: 0 }),
  249. routes: constantRoutes
  250. })
  251. const router = createRouter()
  252. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  253. export function resetRouter() {
  254. const newRouter = createRouter()
  255. router.matcher = newRouter.matcher // reset router
  256. }
  257. export default router