index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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'/'el-icon-x' 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', //访问/的时候会跳转到dashboard
  72. children: [
  73. {
  74. path: 'dashboard',
  75. component: () => import('@/views/dashboard/index'),
  76. name: '首页',
  77. meta: {
  78. title: '首页',
  79. //icon: require('@/assets/public/sidebar/select/index.png'),
  80. iconDefault: require('@/assets/public/sidebar/default/index.png'),
  81. iconSelected: require('@/assets/public/sidebar/select/index.png'),
  82. affix: true ,
  83. }
  84. }
  85. ]
  86. },
  87. //增加新的路由 站点列表
  88. //注意必须含有component:Layout项目否则会导致页面找不到模板
  89. //必须含有children中的path且两个path必须一致
  90. {
  91. path: '/website',
  92. component: Layout,
  93. children: [
  94. {
  95. name: '', //直接就是根目录所以为空
  96. path: '',
  97. component: () => import('@/views/website/WebsiteList'),
  98. meta: {
  99. title: '网站管理', // 设置菜单和面包屑显示的标题
  100. hidden: true, // 不在侧边菜单显示
  101. breadcrumb: true // 强制在面包屑中显示
  102. }
  103. }
  104. ]
  105. },
  106. {
  107. path: '/categoryList',
  108. component: Layout,
  109. children: [
  110. {
  111. name: '', //直接就是根目录所以为空
  112. path: '',
  113. component: () => import('@/views/website/categoryList'),
  114. meta: {
  115. title: '导航池', // 设置菜单和面包屑显示的标题
  116. hidden: true, // 不在侧边菜单显示
  117. breadcrumb: true // 强制在面包屑中显示
  118. }
  119. }
  120. ]
  121. },
  122. {
  123. path: '/websiteColumn',
  124. component: Layout,
  125. children: [
  126. {
  127. name: '', //直接就是根目录所以为空
  128. path: '',
  129. component: () => import('@/views/website/websiteColumn'),
  130. meta: {
  131. title: '网站导航', // 设置菜单和面包屑显示的标题
  132. hidden: true, // 不在侧边菜单显示
  133. breadcrumb: true // 强制在面包屑中显示
  134. }
  135. }
  136. ]
  137. },
  138. // {
  139. // path: '/documentation',
  140. // component: Layout,
  141. // children: [
  142. // {
  143. // path: 'index',
  144. // component: () => import('@/views/documentation/index'),
  145. // name: 'Documentation',
  146. // meta: { title: 'documentation', icon: 'documentation', affix: true }
  147. // }
  148. // ]
  149. // },
  150. // {
  151. // path: '/guide',
  152. // component: Layout,
  153. // redirect: '/guide/index',
  154. // children: [
  155. // {
  156. // path: 'index',
  157. // component: () => import('@/views/guide/index'),
  158. // name: 'Guide',
  159. // meta: { title: 'guide', icon: 'guide', noCache: true }
  160. // }
  161. // ]
  162. // },
  163. {
  164. path: '/profile',
  165. component: Layout,
  166. redirect: '/profile/index',
  167. hidden: true,
  168. children: [
  169. {
  170. path: 'index',
  171. component: () => import('@/views/profile/index'),
  172. name: 'Profile',
  173. meta: { title: 'profile', icon: 'user', noCache: true }
  174. }
  175. ]
  176. }
  177. ]
  178. /**
  179. * asyncRoutes
  180. * the routes that need to be dynamically loaded based on user roles
  181. */
  182. export const asyncRoutes = [
  183. {
  184. path: '/permission',
  185. component: Layout,
  186. redirect: '/permission/page',
  187. alwaysShow: true, // will always show the root menu
  188. name: 'Permission',
  189. meta: {
  190. title: 'permission',
  191. icon: 'lock',
  192. roles: ['admin', 'editor'] // you can set roles in root nav
  193. },
  194. children: [
  195. {
  196. path: 'page',
  197. component: () => import('@/views/permission/page'),
  198. name: 'PagePermission',
  199. meta: {
  200. title: 'pagePermission',
  201. roles: ['admin'] // or you can only set roles in sub nav
  202. }
  203. },
  204. {
  205. path: 'directive',
  206. component: () => import('@/views/permission/directive'),
  207. name: 'DirectivePermission',
  208. meta: {
  209. title: 'directivePermission'
  210. // if do not set roles, means: this page does not require permission
  211. }
  212. },
  213. {
  214. path: 'role',
  215. component: () => import('@/views/permission/role'),
  216. name: 'RolePermission',
  217. meta: {
  218. title: 'rolePermission',
  219. roles: ['admin']
  220. }
  221. }
  222. ]
  223. },
  224. {
  225. path: '/icon',
  226. component: Layout,
  227. children: [
  228. {
  229. path: 'index',
  230. component: () => import('@/views/icons/index'),
  231. name: 'Icons',
  232. meta: { title: 'icons', icon: 'icon', noCache: true }
  233. }
  234. ]
  235. },
  236. /** when your routing map is too long, you can split it into small modules **/
  237. componentsRouter,
  238. chartsRouter,
  239. nestedRouter,
  240. tableRouter,
  241. {
  242. path: '/example',
  243. component: Layout,
  244. redirect: '/example/list',
  245. name: 'Example',
  246. meta: {
  247. title: 'example',
  248. icon: 'el-icon-s-help'
  249. },
  250. children: [
  251. {
  252. path: 'create',
  253. component: () => import('@/views/example/create'),
  254. name: 'CreateArticle',
  255. meta: { title: 'createArticle', icon: 'edit' }
  256. },
  257. {
  258. path: 'edit/:id(\\d+)',
  259. component: () => import('@/views/example/edit'),
  260. name: 'EditArticle',
  261. meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
  262. hidden: true
  263. },
  264. {
  265. path: 'list',
  266. component: () => import('@/views/example/list'),
  267. name: 'ArticleList',
  268. meta: { title: 'articleList', icon: 'list' }
  269. }
  270. ]
  271. },
  272. {
  273. path: '/tab',
  274. component: Layout,
  275. children: [
  276. {
  277. path: 'index',
  278. component: () => import('@/views/tab/index'),
  279. name: 'Tab',
  280. meta: { title: 'tab', icon: 'tab' }
  281. }
  282. ]
  283. },
  284. {
  285. path: '/error',
  286. component: Layout,
  287. redirect: 'noRedirect',
  288. name: 'ErrorPages',
  289. meta: {
  290. title: 'errorPages',
  291. icon: '404'
  292. },
  293. children: [
  294. {
  295. path: '401',
  296. component: () => import('@/views/error-page/401'),
  297. name: 'Page401',
  298. meta: { title: 'page401', noCache: true }
  299. },
  300. {
  301. path: '404',
  302. component: () => import('@/views/error-page/404'),
  303. name: 'Page404',
  304. meta: { title: 'page404', noCache: true }
  305. }
  306. ]
  307. },
  308. {
  309. path: '/error-log',
  310. component: Layout,
  311. children: [
  312. {
  313. path: 'log',
  314. component: () => import('@/views/error-log/index'),
  315. name: 'ErrorLog',
  316. meta: { title: 'errorLog', icon: 'bug' }
  317. }
  318. ]
  319. },
  320. {
  321. path: '/excel',
  322. component: Layout,
  323. redirect: '/excel/export-excel',
  324. name: 'Excel',
  325. meta: {
  326. title: 'excel',
  327. icon: 'excel'
  328. },
  329. children: [
  330. {
  331. path: 'export-excel',
  332. component: () => import('@/views/excel/export-excel'),
  333. name: 'ExportExcel',
  334. meta: { title: 'exportExcel' }
  335. },
  336. {
  337. path: 'export-selected-excel',
  338. component: () => import('@/views/excel/select-excel'),
  339. name: 'SelectExcel',
  340. meta: { title: 'selectExcel' }
  341. },
  342. {
  343. path: 'export-merge-header',
  344. component: () => import('@/views/excel/merge-header'),
  345. name: 'MergeHeader',
  346. meta: { title: 'mergeHeader' }
  347. },
  348. {
  349. path: 'upload-excel',
  350. component: () => import('@/views/excel/upload-excel'),
  351. name: 'UploadExcel',
  352. meta: { title: 'uploadExcel' }
  353. }
  354. ]
  355. },
  356. {
  357. path: '/zip',
  358. component: Layout,
  359. redirect: '/zip/download',
  360. alwaysShow: true,
  361. name: 'Zip',
  362. meta: { title: 'zip', icon: 'zip' },
  363. children: [
  364. {
  365. path: 'download',
  366. component: () => import('@/views/zip/index'),
  367. name: 'ExportZip',
  368. meta: { title: 'exportZip' }
  369. }
  370. ]
  371. },
  372. {
  373. path: '/pdf',
  374. component: Layout,
  375. redirect: '/pdf/index',
  376. children: [
  377. {
  378. path: 'index',
  379. component: () => import('@/views/pdf/index'),
  380. name: 'PDF',
  381. meta: { title: 'pdf', icon: 'pdf' }
  382. }
  383. ]
  384. },
  385. {
  386. path: '/pdf/download',
  387. component: () => import('@/views/pdf/download'),
  388. hidden: true
  389. },
  390. {
  391. path: '/theme',
  392. component: Layout,
  393. children: [
  394. {
  395. path: 'index',
  396. component: () => import('@/views/theme/index'),
  397. name: 'Theme',
  398. meta: { title: 'theme', icon: 'theme' }
  399. }
  400. ]
  401. },
  402. {
  403. path: '/clipboard',
  404. component: Layout,
  405. children: [
  406. {
  407. path: 'index',
  408. component: () => import('@/views/clipboard/index'),
  409. name: 'ClipboardDemo',
  410. meta: { title: 'clipboardDemo', icon: 'clipboard' }
  411. }
  412. ]
  413. },
  414. {
  415. path: '/i18n',
  416. component: Layout,
  417. children: [
  418. {
  419. path: 'index',
  420. component: () => import('@/views/i18n-demo/index'),
  421. name: 'I18n',
  422. meta: { title: 'i18n', icon: 'international' }
  423. }
  424. ]
  425. },
  426. {
  427. path: 'external-link',
  428. component: Layout,
  429. children: [
  430. {
  431. path: 'https://github.com/PanJiaChen/vue-element-admin',
  432. meta: { title: 'externalLink', icon: 'link' }
  433. }
  434. ]
  435. },
  436. // 404 page must be placed at the end !!!
  437. { path: '*', redirect: '/404', hidden: true }
  438. ]
  439. const createRouter = () => new Router({
  440. // mode: 'history', // require service support
  441. scrollBehavior: () => ({ y: 0 }),
  442. routes: constantRoutes
  443. })
  444. const router = createRouter()
  445. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  446. export function resetRouter() {
  447. const newRouter = createRouter()
  448. router.matcher = newRouter.matcher // reset router
  449. }
  450. export default router