router.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import { packages } from '@/config.json';
  4. import vueg from 'vueg';
  5. const Index = () => import(/* webpackChunkName: "demo-index" */ './view/index.vue');
  6. const DemoNav = () => import(/* webpackChunkName: "demo-demonav" */'./view/demonav.vue');
  7. // import Index from './view/index.vue';
  8. // import DemoNav from './view/demonav.vue';
  9. Vue.use(VueRouter);
  10. const routes = [
  11. {
  12. path: '*',
  13. redirect: '/index'
  14. },
  15. {
  16. name:'index',
  17. path: '/index',
  18. components: {
  19. main: Index,
  20. demonav: DemoNav,
  21. }
  22. },
  23. ];
  24. //组件示例页面
  25. packages.map(item => {
  26. if (item.showDemo === false) return;
  27. const pkgName = item.name.toLowerCase();
  28. routes.push({
  29. path: '/' + item.name,
  30. components: {
  31. main: () => import(
  32. /* webpackChunkName: "demo-[request]" */
  33. `@/packages/${pkgName}/demo.vue`),
  34. demonav: DemoNav
  35. },
  36. name: item.name
  37. });
  38. });
  39. const router = new VueRouter({
  40. routes,
  41. scrollBehavior(to, from, savedPosition) {
  42. if (to.path == '/index') {
  43. return null;
  44. } else {
  45. return { x: 0, y: 0 }
  46. }
  47. }
  48. });
  49. const options = {
  50. duration: '0.2', //转场动画时长,默认为0.3,单位秒
  51. firstEntryDisable: true, //值为true时禁用首次进入应用时的渐现动画,默认为false
  52. firstEntryDuration: '.3', //首次进入应用时的渐现动画时长,默认为.6
  53. forwardAnim: 'fadeInRight', //前进动画,默认为fadeInRight
  54. backAnim: 'fadeInLeft', //后退动画,默认为fedeInLeft
  55. sameDepthDisable: false, //url深度相同时禁用动画,默认为false
  56. tabs: [], //默认为[],'name'对应路由的name,以实现类似app中点击tab页面水平转场效果,如tabs[1]到tabs[0],会使用backAnim动画,tabs[1]到tabs[2],会使用forwardAnim动画
  57. tabsDisable: false, //值为true时,tabs间的转场没有动画,默认为false
  58. shadow: false, //值为false,转场时没有阴影的层次效果
  59. disable: false, //禁用转场动画,默认为false,嵌套路由默认为true
  60. };
  61. Vue.use(vueg, router, options);
  62. export default router;