router.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. const importPage = view => () => import(/* webpackChunkName: "p-[request]" */ `./views/${view}.vue`)
  4. const importLayout = view => () => import(/* webpackChunkName: "ly-[request]" */ `./components/layout/${view}.vue`)
  5. Vue.use(Router)
  6. // 路由页面
  7. let pageRoutes = [{
  8. path: 'page/:id',
  9. component: importPage('Page'),
  10. meta: {
  11. title: '页面',
  12. icon: 'rt-icon-doc'
  13. }
  14. }, {
  15. path: 'rule/:catalog/:type',
  16. component: importPage('Rule'),
  17. meta: {
  18. title: '默认规则',
  19. icon: 'rt-icon-log'
  20. }
  21. }, {
  22. path: 'route-rule/:catalog/:type',
  23. component: importPage('Rule'),
  24. meta: {
  25. title: '路由规则',
  26. icon: 'rt-icon-log',
  27. aliveId (route) {
  28. return `route-rule/${route.params.catalog}`
  29. }
  30. }
  31. }, {
  32. path: 'tab-dynamic',
  33. component: importPage('TabDynamic'),
  34. meta: {
  35. title: '动态更新页签',
  36. icon: 'rt-icon-log'
  37. }
  38. }, {
  39. path: 'page-leave',
  40. component: importPage('PageLeave'),
  41. meta: {
  42. title: '页面离开确认',
  43. icon: 'rt-icon-contact'
  44. }
  45. }]
  46. export default new Router({
  47. routes: [{
  48. path: '/',
  49. redirect: '/default/page/1'
  50. }, {
  51. path: '/default/',
  52. component: importLayout('Default'),
  53. redirect: '/default/page/1',
  54. children: pageRoutes
  55. }, {
  56. path: '/transition/',
  57. component: importLayout('Transition'),
  58. redirect: '/transition/page/1',
  59. children: pageRoutes
  60. }, {
  61. path: '/initial-tabs/',
  62. component: importLayout('InitialTabs'),
  63. redirect: '/initial-tabs/page/1',
  64. children: pageRoutes
  65. }, {
  66. path: '/lang-en/',
  67. component: importLayout('LangEn'),
  68. redirect: '/lang-en/page/1',
  69. children: pageRoutes
  70. }, {
  71. path: '/lang-custom/',
  72. component: importLayout('LangCustom'),
  73. redirect: '/lang-custom/page/1',
  74. children: pageRoutes
  75. }, {
  76. path: '/slot/',
  77. component: importLayout('Slot'),
  78. redirect: '/slot/page/1',
  79. children: pageRoutes
  80. }, {
  81. path: '/global-rule/',
  82. component: importLayout('GlobalRule'),
  83. redirect: '/global-rule/rule/a/1',
  84. children: pageRoutes
  85. }, {
  86. path: '/404',
  87. component: importPage('404'),
  88. meta: {
  89. title: '找不到页面',
  90. icon: 'rt-icon-warning'
  91. }
  92. }, {
  93. path: '*',
  94. redirect: '/404'
  95. }]
  96. })