router.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import { packages } from '@/config.json';
  4. import frontCover from './index.vue';
  5. const Index = () => import(/* webpackPrefetch: true */ /* webpackChunkName: 'info' */ './info.vue');
  6. const Intro = () => import(/* webpackPrefetch: true */ /* webpackChunkName: 'intro' */ './page/intro.vue');
  7. const Start = () => import(/* webpackPrefetch: true */ /* webpackChunkName: 'start' */ './page/start.vue');
  8. const International = () => import(/* webpackPrefetch: true */ /* webpackChunkName: 'international' */ './page/international.vue');
  9. const Theme = () => import(/* webpackPrefetch: true */ /* webpackChunkName: 'theme' */ './page/theme.vue');
  10. const JoinUs = () => import(/* webpackPrefetch: true */ /* webpackChunkName: 'joinus' */ './page/joinus.vue');
  11. //const Update = () => import('./page/changelog.vue');
  12. Vue.use(VueRouter);
  13. const routes = [
  14. {
  15. path: '*',
  16. redirect: '/index'
  17. },
  18. {
  19. path: '/',
  20. redirect: '/index'
  21. },
  22. {
  23. path: '/index',
  24. name: 'frontcover',
  25. component: frontCover
  26. },
  27. {
  28. path: '/intro',
  29. name: 'intr',
  30. components: {
  31. default: Index,
  32. main: Intro
  33. }
  34. },
  35. {
  36. path: '/international',
  37. name: 'international',
  38. components: {
  39. default: Index,
  40. main: International
  41. }
  42. },
  43. {
  44. path: '/start',
  45. name: 'start',
  46. components: {
  47. default: Index,
  48. main: Start
  49. }
  50. },
  51. {
  52. path: '/theme',
  53. name: 'theme',
  54. components: {
  55. default: Index,
  56. main: Theme
  57. }
  58. },
  59. {
  60. path: '/joinus',
  61. name: 'joinus',
  62. components: {
  63. default: Index,
  64. main: JoinUs
  65. }
  66. }
  67. ];
  68. //组件md文件展示
  69. packages.map(item => {
  70. if (item.showDemo === false) return;
  71. const pkgName = item.name.toLowerCase();
  72. routes.push({
  73. path: '/' + item.name,
  74. components: {
  75. default: Index,
  76. main: () => import('./view/' + pkgName + '.vue')
  77. },
  78. name: item.name
  79. });
  80. });
  81. const router = new VueRouter({
  82. routes,
  83. scrollBehavior(to, from, savedPosition) {
  84. if (to.path == '/index') {
  85. return null;
  86. } else {
  87. return { x: 0, y: 0 };
  88. }
  89. }
  90. });
  91. export default router;