router.js 2.7 KB

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