router.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import Conf from '../config.json';
  4. const Nav = () => import('./view/nav.vue');
  5. const Intro = () => import('./view/intro.vue');
  6. const Phone = () => import('./view/phone.vue');
  7. const Cases = () => import('./view/cases.vue');
  8. Vue.use(VueRouter);
  9. const routes = [
  10. {
  11. name:'/',
  12. path: '/',
  13. redirect: '/intro'
  14. },
  15. {
  16. name:'intro',
  17. path: '/intro',
  18. components:{
  19. nav:Nav,
  20. main:Intro
  21. }
  22. },
  23. {
  24. name:'nutdemo',
  25. path: '/nutdemo',
  26. components:{
  27. nav:Nav,
  28. phone:Phone,
  29. }
  30. },
  31. {
  32. name:'cases',
  33. path: '/cases',
  34. components:{
  35. main:Cases,
  36. }
  37. }
  38. ];
  39. //组件文档页面
  40. Conf.packages.map(item => {
  41. routes.push({
  42. name: item.name,
  43. path: '/' + item.name,
  44. components: {
  45. nav: Nav,
  46. main: () => import('./view/' + item.name.toLowerCase() + '.vue'),
  47. }
  48. });
  49. });
  50. const router = new VueRouter({
  51. routes,
  52. scrollBehavior(to, from, savedPosition) {
  53. return { x: 0, y: 0 }
  54. }
  55. });
  56. export default router;