router.js 2.1 KB

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