index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. import shopRouter from '@/router/modules/shop'
  12. import profileRouter from '@/router/modules/profileRouter'
  13. /**
  14. * Note: sub-menu only appear when route children.length >= 1
  15. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  16. *
  17. * hidden: true if set true, item will not show in the sidebar(default is false)
  18. * alwaysShow: true if set true, will always show the root menu
  19. * if not set alwaysShow, when item has more than one children route,
  20. * it will becomes nested mode, otherwise not show the root menu
  21. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  22. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  23. * meta : {
  24. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  25. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  26. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  27. noCache: true if set true, the page will no be cached(default is false)
  28. affix: true if set true, the tag will affix in the tags-view
  29. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  30. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  31. }
  32. */
  33. /**
  34. * constantRoutes
  35. * a base page that does not have permission requirements
  36. * all roles can be accessed
  37. */
  38. export const constantRoutes = [
  39. {
  40. path: '/redirect',
  41. component: Layout,
  42. hidden: true,
  43. children: [
  44. {
  45. path: '/redirect/:path(.*)',
  46. component: () => import('@/views/redirect/index')
  47. }
  48. ]
  49. },
  50. {
  51. path: '/login',
  52. component: () => import('@/views/login/index'),
  53. hidden: true,
  54. meta: { title: '会员管理系统' }
  55. },
  56. {
  57. path: '/auth-redirect',
  58. component: () => import('@/views/login/auth-redirect'),
  59. hidden: true
  60. },
  61. {
  62. path: '/login-by-backend',
  63. component: () => import('@/views/login/login-by-backend'),
  64. name: 'login-by-backend'
  65. },
  66. {
  67. path: '/404',
  68. component: () => import('@/views/error-page/404'),
  69. hidden: true
  70. },
  71. {
  72. path: '/401',
  73. component: () => import('@/views/error-page/401'),
  74. hidden: true
  75. },
  76. {
  77. path: '/',
  78. component: Layout,
  79. redirect: '/dashboard/index',
  80. children: [
  81. {
  82. path: 'dashboard/index',
  83. component: () => import('@/views/dashboard/index'),
  84. name: 'Dashboard',
  85. meta: { title: 'dashboard', icon: 'dashboard', affix: true }
  86. }
  87. ]
  88. }
  89. // {
  90. // path: '/dashboard/index',
  91. // component: Layout,
  92. // redirect: '/dashboard',
  93. // children: [
  94. // {
  95. // path: 'dashboard',
  96. // component: () => import('@/views/dashboard/index'),
  97. // name: 'Dashboard',
  98. // meta: { title: 'dashboard', icon: 'dashboard', affix: true }
  99. // }
  100. // ]
  101. // },
  102. // {
  103. // path: '/documentation',
  104. // component: Layout,
  105. // children: [
  106. // {
  107. // path: 'index',
  108. // component: () => import('@/views/documentation/index'),
  109. // name: 'Documentation',
  110. // meta: { title: 'documentation', icon: 'documentation', affix: true }
  111. // }
  112. // ]
  113. // },
  114. // {
  115. // path: '/guide',
  116. // component: Layout,
  117. // redirect: '/guide/index',
  118. // children: [
  119. // {
  120. // path: 'index',
  121. // component: () => import('@/views/guide/index'),
  122. // name: 'Guide',
  123. // meta: { title: 'guide', icon: 'guide', noCache: true }
  124. // }
  125. // ]
  126. // },
  127. ]
  128. /**
  129. * asyncRoutes
  130. * the routes that need to be dynamically loaded based on user roles
  131. */
  132. export const asyncRoutes = [
  133. {
  134. path: '/permission',
  135. component: Layout,
  136. redirect: '/permission/page',
  137. alwaysShow: true, // will always show the root menu
  138. name: 'Permission',
  139. meta: {
  140. title: 'permission',
  141. icon: 'lock',
  142. roles: ['admin', 'editor'] // you can set roles in root nav
  143. },
  144. children: [
  145. {
  146. path: 'page',
  147. component: () => import('@/views/permission/page'),
  148. name: 'PagePermission',
  149. meta: {
  150. title: 'pagePermission',
  151. roles: ['admin'] // or you can only set roles in sub nav
  152. }
  153. },
  154. {
  155. path: 'directive',
  156. component: () => import('@/views/permission/directive'),
  157. name: 'DirectivePermission',
  158. meta: {
  159. title: 'directivePermission'
  160. // if do not set roles, means: this page does not require permission
  161. }
  162. },
  163. {
  164. path: 'role',
  165. component: () => import('@/views/permission/role'),
  166. name: 'RolePermission',
  167. meta: {
  168. title: 'rolePermission',
  169. roles: ['admin']
  170. }
  171. }
  172. ]
  173. },
  174. {
  175. path: '/icon',
  176. component: Layout,
  177. children: [
  178. {
  179. path: 'index',
  180. component: () => import('@/views/icons/index'),
  181. name: 'Icons',
  182. meta: { title: 'icons', icon: 'icon', noCache: true }
  183. }
  184. ]
  185. },
  186. /** when your routing map is too long, you can split it into small modules **/
  187. componentsRouter,
  188. chartsRouter,
  189. nestedRouter,
  190. tableRouter,
  191. shopRouter,
  192. profileRouter,
  193. // {
  194. // path: '/example',
  195. // component: Layout,
  196. // redirect: '/example/list',
  197. // name: 'Example',
  198. // meta: {
  199. // title: 'example',
  200. // icon: 'el-icon-s-help'
  201. // },
  202. // children: [
  203. // {
  204. // path: 'create',
  205. // component: () => import('@/views/example/create'),
  206. // name: 'CreateArticle',
  207. // meta: { title: 'createArticle', icon: 'edit' }
  208. // },
  209. // {
  210. // path: 'edit/:id(\\d+)',
  211. // component: () => import('@/views/example/edit'),
  212. // name: 'EditArticle',
  213. // meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
  214. // hidden: true
  215. // },
  216. // {
  217. // path: 'list',
  218. // component: () => import('@/views/example/list'),
  219. // name: 'ArticleList',
  220. // meta: { title: 'articleList', icon: 'list' }
  221. // }
  222. // ]
  223. // },
  224. // {
  225. // path: '/tab',
  226. // component: Layout,
  227. // children: [
  228. // {
  229. // path: 'index',
  230. // component: () => import('@/views/tab/index'),
  231. // name: 'Tab',
  232. // meta: { title: 'tab', icon: 'tab' }
  233. // }
  234. // ]
  235. // },
  236. {
  237. path: '/error',
  238. component: Layout,
  239. redirect: 'noRedirect',
  240. name: 'ErrorPages',
  241. meta: {
  242. title: 'errorPages',
  243. icon: '404'
  244. },
  245. children: [
  246. {
  247. path: '401',
  248. component: () => import('@/views/error-page/401'),
  249. name: 'Page401',
  250. meta: { title: 'page401', noCache: true }
  251. },
  252. {
  253. path: '404',
  254. component: () => import('@/views/error-page/404'),
  255. name: 'Page404',
  256. meta: { title: 'page404', noCache: true }
  257. }
  258. ]
  259. },
  260. {
  261. path: '/error-log',
  262. component: Layout,
  263. children: [
  264. {
  265. path: 'log',
  266. component: () => import('@/views/error-log/index'),
  267. name: 'ErrorLog',
  268. meta: { title: 'errorLog', icon: 'bug' }
  269. }
  270. ]
  271. },
  272. // {
  273. // path: '/excel',
  274. // component: Layout,
  275. // redirect: '/excel/export-excel',
  276. // name: 'Excel',
  277. // meta: {
  278. // title: 'excel',
  279. // icon: 'excel'
  280. // },
  281. // children: [
  282. // {
  283. // path: 'export-excel',
  284. // component: () => import('@/views/excel/export-excel'),
  285. // name: 'ExportExcel',
  286. // meta: { title: 'exportExcel' }
  287. // },
  288. // {
  289. // path: 'export-selected-excel',
  290. // component: () => import('@/views/excel/select-excel'),
  291. // name: 'SelectExcel',
  292. // meta: { title: 'selectExcel' }
  293. // },
  294. // {
  295. // path: 'export-merge-header',
  296. // component: () => import('@/views/excel/merge-header'),
  297. // name: 'MergeHeader',
  298. // meta: { title: 'mergeHeader' }
  299. // },
  300. // {
  301. // path: 'upload-excel',
  302. // component: () => import('@/views/excel/upload-excel'),
  303. // name: 'UploadExcel',
  304. // meta: { title: 'uploadExcel' }
  305. // }
  306. // ]
  307. // },
  308. //
  309. // {
  310. // path: '/zip',
  311. // component: Layout,
  312. // redirect: '/zip/download',
  313. // alwaysShow: true,
  314. // name: 'Zip',
  315. // meta: { title: 'zip', icon: 'zip' },
  316. // children: [
  317. // {
  318. // path: 'download',
  319. // component: () => import('@/views/zip/index'),
  320. // name: 'ExportZip',
  321. // meta: { title: 'exportZip' }
  322. // }
  323. // ]
  324. // },
  325. //
  326. // {
  327. // path: '/pdf',
  328. // component: Layout,
  329. // redirect: '/pdf/index',
  330. // children: [
  331. // {
  332. // path: 'index',
  333. // component: () => import('@/views/pdf/index'),
  334. // name: 'PDF',
  335. // meta: { title: 'pdf', icon: 'pdf' }
  336. // }
  337. // ]
  338. // },
  339. // {
  340. // path: '/pdf/download',
  341. // component: () => import('@/views/pdf/download'),
  342. // hidden: true
  343. // },
  344. //
  345. // {
  346. // path: '/theme',
  347. // component: Layout,
  348. // children: [
  349. // {
  350. // path: 'index',
  351. // component: () => import('@/views/theme/index'),
  352. // name: 'Theme',
  353. // meta: { title: 'theme', icon: 'theme' }
  354. // }
  355. // ]
  356. // },
  357. //
  358. // {
  359. // path: '/clipboard',
  360. // component: Layout,
  361. // children: [
  362. // {
  363. // path: 'index',
  364. // component: () => import('@/views/clipboard/index'),
  365. // name: 'ClipboardDemo',
  366. // meta: { title: 'clipboardDemo', icon: 'clipboard' }
  367. // }
  368. // ]
  369. // },
  370. // {
  371. // path: '/i18n',
  372. // component: Layout,
  373. // children: [
  374. // {
  375. // path: 'index',
  376. // component: () => import('@/views/i18n-demo/index'),
  377. // name: 'I18n',
  378. // meta: { title: 'i18n', icon: 'international' }
  379. // }
  380. // ]
  381. // },
  382. //
  383. // {
  384. // path: 'external-link',
  385. // component: Layout,
  386. // children: [
  387. // {
  388. // path: 'https://github.com/PanJiaChen/vue-element-admin',
  389. // meta: { title: 'externalLink', icon: 'link' }
  390. // }
  391. // ]
  392. // },
  393. // 404 page must be placed at the end !!!
  394. { path: '*', redirect: '/404', hidden: true }
  395. ]
  396. const createRouter = () => new Router({
  397. // mode: 'history', // require service support
  398. scrollBehavior: () => ({ y: 0 }),
  399. routes: constantRoutes.concat(asyncRoutes)
  400. // routes: constantRoutes.concat(asyncRoutes)
  401. })
  402. const router = createRouter()
  403. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  404. export function resetRouter() {
  405. const newRouter = createRouter()
  406. router.matcher = newRouter.matcher // reset router
  407. }
  408. export function selfAddRoutes(params) {
  409. const newRouter = createRouter()
  410. router.matcher = newRouter.matcher
  411. router.addRoutes(params)
  412. }
  413. export default router