index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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: '/redirect',
  39. component: Layout,
  40. hidden: true,
  41. children: [
  42. {
  43. path: '/redirect/:path(.*)',
  44. component: () => import('@/views/redirect/index')
  45. }
  46. ]
  47. },
  48. {
  49. path: '/login',
  50. component: () => import('@/views/login/index'),
  51. hidden: true
  52. },
  53. {
  54. path: '/auth-redirect',
  55. component: () => import('@/views/login/auth-redirect'),
  56. hidden: true
  57. },
  58. {
  59. path: '/404',
  60. component: () => import('@/views/error-page/404'),
  61. hidden: true
  62. },
  63. {
  64. path: '/401',
  65. component: () => import('@/views/error-page/401'),
  66. hidden: true
  67. },
  68. {
  69. path: '/',
  70. component: Layout,
  71. redirect: '/dashboard',
  72. children: [
  73. {
  74. path: 'dashboard',
  75. component: () => import('@/views/dashboard/index'),
  76. name: 'Dashboard',
  77. meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
  78. }
  79. ]
  80. }
  81. ]
  82. /**
  83. * asyncRoutes
  84. * the routes that need to be dynamically loaded based on user roles
  85. */
  86. export const asyncRoutes = [
  87. {
  88. path: '/documentation',
  89. component: Layout,
  90. children: [
  91. {
  92. path: 'index',
  93. component: () => import('@/views/documentation/index'),
  94. name: 'Documentation',
  95. meta: { title: 'Documentation', icon: 'documentation', affix: true }
  96. }
  97. ]
  98. },
  99. {
  100. path: '/guide',
  101. component: Layout,
  102. redirect: '/guide/index',
  103. children: [
  104. {
  105. path: 'index',
  106. component: () => import('@/views/guide/index'),
  107. name: 'Guide',
  108. meta: { title: 'Guide', icon: 'guide', noCache: true }
  109. }
  110. ]
  111. },
  112. {
  113. path: '/profile',
  114. component: Layout,
  115. redirect: '/profile/index',
  116. hidden: true,
  117. children: [
  118. {
  119. path: 'index',
  120. component: () => import('@/views/profile/index'),
  121. name: 'Profile',
  122. meta: { title: 'Profile', icon: 'user', noCache: true }
  123. }
  124. ]
  125. },
  126. {
  127. path: '/permission',
  128. component: Layout,
  129. redirect: '/permission/page',
  130. alwaysShow: true, // will always show the root menu
  131. name: 'Permission',
  132. meta: {
  133. title: 'Permission',
  134. icon: 'lock',
  135. roles: ['admin', 'editor'] // you can set roles in root nav
  136. },
  137. children: [
  138. {
  139. path: 'page',
  140. component: () => import('@/views/permission/page'),
  141. name: 'PagePermission',
  142. meta: {
  143. title: 'Page Permission',
  144. roles: ['admin'] // or you can only set roles in sub nav
  145. }
  146. },
  147. {
  148. path: 'directive',
  149. component: () => import('@/views/permission/directive'),
  150. name: 'DirectivePermission',
  151. meta: {
  152. title: 'Directive Permission'
  153. // if do not set roles, means: this page does not require permission
  154. }
  155. },
  156. {
  157. path: 'role',
  158. component: () => import('@/views/permission/role'),
  159. name: 'RolePermission',
  160. meta: {
  161. title: 'Role Permission',
  162. roles: ['admin']
  163. }
  164. }
  165. ]
  166. },
  167. {
  168. path: '/icon',
  169. component: Layout,
  170. children: [
  171. {
  172. path: 'index',
  173. component: () => import('@/views/icons/index'),
  174. name: 'Icons',
  175. meta: { title: 'Icons', icon: 'icon', noCache: true }
  176. }
  177. ]
  178. },
  179. componentsRouter,
  180. chartsRouter,
  181. nestedRouter,
  182. tableRouter,
  183. {
  184. path: '/example',
  185. component: Layout,
  186. redirect: '/example/list',
  187. name: 'Example',
  188. meta: {
  189. title: 'Example',
  190. icon: 'example'
  191. },
  192. children: [
  193. {
  194. path: 'create',
  195. component: () => import('@/views/example/create'),
  196. name: 'CreateArticle',
  197. meta: { title: 'Create Article', icon: 'edit' }
  198. },
  199. {
  200. path: 'edit/:id(\\d+)',
  201. component: () => import('@/views/example/edit'),
  202. name: 'EditArticle',
  203. meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
  204. hidden: true
  205. },
  206. {
  207. path: 'list',
  208. component: () => import('@/views/example/list'),
  209. name: 'ArticleList',
  210. meta: { title: 'Article List', icon: 'list' }
  211. }
  212. ]
  213. },
  214. {
  215. path: '/tab',
  216. component: Layout,
  217. children: [
  218. {
  219. path: 'index',
  220. component: () => import('@/views/tab/index'),
  221. name: 'Tab',
  222. meta: { title: 'Tab', icon: 'tab' }
  223. }
  224. ]
  225. },
  226. {
  227. path: '/error',
  228. component: Layout,
  229. redirect: 'noRedirect',
  230. name: 'ErrorPages',
  231. meta: {
  232. title: 'Error Pages',
  233. icon: '404'
  234. },
  235. children: [
  236. {
  237. path: '401',
  238. component: () => import('@/views/error-page/401'),
  239. name: 'Page401',
  240. meta: { title: '401', noCache: true }
  241. },
  242. {
  243. path: '404',
  244. component: () => import('@/views/error-page/404'),
  245. name: 'Page404',
  246. meta: { title: '404', noCache: true }
  247. }
  248. ]
  249. },
  250. {
  251. path: '/error-log',
  252. component: Layout,
  253. children: [
  254. {
  255. path: 'log',
  256. component: () => import('@/views/error-log/index'),
  257. name: 'ErrorLog',
  258. meta: { title: 'Error Log', icon: 'bug' }
  259. }
  260. ]
  261. },
  262. {
  263. path: '/excel',
  264. component: Layout,
  265. redirect: '/excel/export-excel',
  266. name: 'Excel',
  267. meta: {
  268. title: 'Excel',
  269. icon: 'excel'
  270. },
  271. children: [
  272. {
  273. path: 'export-excel',
  274. component: () => import('@/views/excel/export-excel'),
  275. name: 'ExportExcel',
  276. meta: { title: 'Export Excel' }
  277. },
  278. {
  279. path: 'export-selected-excel',
  280. component: () => import('@/views/excel/select-excel'),
  281. name: 'SelectExcel',
  282. meta: { title: 'Export Selected' }
  283. },
  284. {
  285. path: 'export-merge-header',
  286. component: () => import('@/views/excel/merge-header'),
  287. name: 'MergeHeader',
  288. meta: { title: 'Merge Header' }
  289. },
  290. {
  291. path: 'upload-excel',
  292. component: () => import('@/views/excel/upload-excel'),
  293. name: 'UploadExcel',
  294. meta: { title: 'Upload Excel' }
  295. }
  296. ]
  297. },
  298. {
  299. path: '/zip',
  300. component: Layout,
  301. redirect: '/zip/download',
  302. alwaysShow: true,
  303. name: 'Zip',
  304. meta: { title: 'Zip', icon: 'zip' },
  305. children: [
  306. {
  307. path: 'download',
  308. component: () => import('@/views/zip/index'),
  309. name: 'ExportZip',
  310. meta: { title: 'Export Zip' }
  311. }
  312. ]
  313. },
  314. {
  315. path: '/pdf',
  316. component: Layout,
  317. redirect: '/pdf/index',
  318. children: [
  319. {
  320. path: 'index',
  321. component: () => import('@/views/pdf/index'),
  322. name: 'PDF',
  323. meta: { title: 'PDF', icon: 'pdf' }
  324. }
  325. ]
  326. },
  327. {
  328. path: '/pdf/download',
  329. component: () => import('@/views/pdf/download'),
  330. hidden: true
  331. },
  332. {
  333. path: '/theme',
  334. component: Layout,
  335. children: [
  336. {
  337. path: 'index',
  338. component: () => import('@/views/theme/index'),
  339. name: 'Theme',
  340. meta: { title: 'Theme', icon: 'theme' }
  341. }
  342. ]
  343. },
  344. {
  345. path: '/clipboard',
  346. component: Layout,
  347. children: [
  348. {
  349. path: 'index',
  350. component: () => import('@/views/clipboard/index'),
  351. name: 'ClipboardDemo',
  352. meta: { title: 'Clipboard', icon: 'clipboard' }
  353. }
  354. ]
  355. },
  356. {
  357. path: 'external-link',
  358. component: Layout,
  359. children: [
  360. {
  361. path: 'https://github.com/PanJiaChen/vue-element-admin',
  362. meta: { title: 'External Link', icon: 'link' }
  363. }
  364. ]
  365. },
  366. // 404 page must be placed at the end !!!
  367. { path: '*', redirect: '/404', hidden: true }
  368. ]
  369. const createRouter = () => new Router({
  370. // mode: 'history', // require service support
  371. scrollBehavior: () => ({ y: 0 }),
  372. routes: constantRoutes
  373. })
  374. const router = createRouter()
  375. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  376. export function resetRouter() {
  377. const newRouter = createRouter()
  378. router.matcher = newRouter.matcher // reset router
  379. }
  380. export default router