index3.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. path: '/documentation',
  83. component: Layout,
  84. children: [
  85. {
  86. path: 'index',
  87. component: () => import('@/views/documentation/index'),
  88. name: 'Documentation',
  89. meta: { title: 'Documentation', icon: 'documentation', affix: true }
  90. }
  91. ]
  92. },
  93. {
  94. path: '/guide',
  95. component: Layout,
  96. redirect: '/guide/index',
  97. children: [
  98. {
  99. path: 'index',
  100. component: () => import('@/views/guide/index'),
  101. name: 'Guide',
  102. meta: { title: 'Guide', icon: 'guide', noCache: true }
  103. }
  104. ]
  105. },
  106. {
  107. path: '/profile',
  108. component: Layout,
  109. redirect: '/profile/index',
  110. hidden: true,
  111. children: [
  112. {
  113. path: 'index',
  114. component: () => import('@/views/profile/index'),
  115. name: 'Profile',
  116. meta: { title: 'Profile', icon: 'user', noCache: true }
  117. }
  118. ]
  119. }
  120. ]
  121. /**
  122. * asyncRoutes
  123. * the routes that need to be dynamically loaded based on user roles
  124. */
  125. export const asyncRoutes = [
  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. /** when your routing map is too long, you can split it into small modules **/
  180. componentsRouter,
  181. chartsRouter,
  182. nestedRouter,
  183. tableRouter,
  184. {
  185. path: '/example',
  186. component: Layout,
  187. redirect: '/example/list',
  188. name: 'Example',
  189. meta: {
  190. title: 'Example',
  191. icon: 'example'
  192. },
  193. children: [
  194. {
  195. path: 'create',
  196. component: () => import('@/views/example/create'),
  197. name: 'CreateArticle',
  198. meta: { title: 'Create Article', icon: 'edit' }
  199. },
  200. {
  201. path: 'edit/:id(\\d+)',
  202. component: () => import('@/views/example/edit'),
  203. name: 'EditArticle',
  204. meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
  205. hidden: true
  206. },
  207. {
  208. path: 'list',
  209. component: () => import('@/views/example/list'),
  210. name: 'ArticleList',
  211. meta: { title: 'Article List', icon: 'list' }
  212. }
  213. ]
  214. },
  215. {
  216. path: '/tab',
  217. component: Layout,
  218. children: [
  219. {
  220. path: 'index',
  221. component: () => import('@/views/tab/index'),
  222. name: 'Tab',
  223. meta: { title: 'Tab', icon: 'tab' }
  224. }
  225. ]
  226. },
  227. {
  228. path: '/error',
  229. component: Layout,
  230. redirect: 'noRedirect',
  231. name: 'ErrorPages',
  232. meta: {
  233. title: 'Error Pages',
  234. icon: '404'
  235. },
  236. children: [
  237. {
  238. path: '401',
  239. component: () => import('@/views/error-page/401'),
  240. name: 'Page401',
  241. meta: { title: '401', noCache: true }
  242. },
  243. {
  244. path: '404',
  245. component: () => import('@/views/error-page/404'),
  246. name: 'Page404',
  247. meta: { title: '404', noCache: true }
  248. }
  249. ]
  250. },
  251. {
  252. path: '/error-log',
  253. component: Layout,
  254. children: [
  255. {
  256. path: 'log',
  257. component: () => import('@/views/error-log/index'),
  258. name: 'ErrorLog',
  259. meta: { title: 'Error Log', icon: 'bug' }
  260. }
  261. ]
  262. },
  263. {
  264. path: '/excel',
  265. component: Layout,
  266. redirect: '/excel/export-excel',
  267. name: 'Excel',
  268. meta: {
  269. title: 'Excel',
  270. icon: 'excel'
  271. },
  272. children: [
  273. {
  274. path: 'export-excel',
  275. component: () => import('@/views/excel/export-excel'),
  276. name: 'ExportExcel',
  277. meta: { title: 'Export Excel' }
  278. },
  279. {
  280. path: 'export-selected-excel',
  281. component: () => import('@/views/excel/select-excel'),
  282. name: 'SelectExcel',
  283. meta: { title: 'Export Selected' }
  284. },
  285. {
  286. path: 'export-merge-header',
  287. component: () => import('@/views/excel/merge-header'),
  288. name: 'MergeHeader',
  289. meta: { title: 'Merge Header' }
  290. },
  291. {
  292. path: 'upload-excel',
  293. component: () => import('@/views/excel/upload-excel'),
  294. name: 'UploadExcel',
  295. meta: { title: 'Upload Excel' }
  296. }
  297. ]
  298. },
  299. {
  300. path: '/zip',
  301. component: Layout,
  302. redirect: '/zip/download',
  303. alwaysShow: true,
  304. name: 'Zip',
  305. meta: { title: 'Zip', icon: 'zip' },
  306. children: [
  307. {
  308. path: 'download',
  309. component: () => import('@/views/zip/index'),
  310. name: 'ExportZip',
  311. meta: { title: 'Export Zip' }
  312. }
  313. ]
  314. },
  315. {
  316. path: '/pdf',
  317. component: Layout,
  318. redirect: '/pdf/index',
  319. children: [
  320. {
  321. path: 'index',
  322. component: () => import('@/views/pdf/index'),
  323. name: 'PDF',
  324. meta: { title: 'PDF', icon: 'pdf' }
  325. }
  326. ]
  327. },
  328. {
  329. path: '/pdf/download',
  330. component: () => import('@/views/pdf/download'),
  331. hidden: true
  332. },
  333. {
  334. path: '/theme',
  335. component: Layout,
  336. children: [
  337. {
  338. path: 'index',
  339. component: () => import('@/views/theme/index'),
  340. name: 'Theme',
  341. meta: { title: 'Theme', icon: 'theme' }
  342. }
  343. ]
  344. },
  345. {
  346. path: '/clipboard',
  347. component: Layout,
  348. children: [
  349. {
  350. path: 'index',
  351. component: () => import('@/views/clipboard/index'),
  352. name: 'ClipboardDemo',
  353. meta: { title: 'Clipboard', icon: 'clipboard' }
  354. }
  355. ]
  356. },
  357. {
  358. path: 'external-link',
  359. component: Layout,
  360. children: [
  361. {
  362. path: 'https://github.com/PanJiaChen/vue-element-admin',
  363. meta: { title: 'External Link', icon: 'link' }
  364. }
  365. ]
  366. },
  367. // 404 page must be placed at the end !!!
  368. { path: '*', redirect: '/404', hidden: true }
  369. ]
  370. const createRouter = () => new Router({
  371. // mode: 'history', // require service support
  372. scrollBehavior: () => ({ y: 0 }),
  373. routes: constantRoutes
  374. })
  375. const router = createRouter()
  376. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  377. export function resetRouter() {
  378. const newRouter = createRouter()
  379. router.matcher = newRouter.matcher // reset router
  380. }
  381. export default router