index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // //创建一个路由器
  2. import { createRouter, createWebHashHistory, } from "vue-router";
  3. import configurator from "@/view/configurator.vue"
  4. import resultLeft from '@/view/result/resultLeft.vue';
  5. import resultRight from '@/view/result/resultRight.vue';
  6. import result from '@/view/result.vue';
  7. const router = createRouter({
  8. history: createWebHashHistory(),
  9. routes: [
  10. {
  11. path: '/myHome',
  12. component: () => import('@/components/myHome.vue') // 这是路由的籁加载,也可以其他方式
  13. },
  14. {
  15. path: '/configurator',
  16. name:'模型库',
  17. component: configurator,// 这是路由的籁加载,也可以其他方式
  18. beforeEnter: (to, from,next) => {
  19. console.log(to, from);
  20. next()
  21. },
  22. },
  23. {
  24. path: '/',
  25. name:'首页',
  26. component: () => import('@/view/home.vue'),
  27. meta:{
  28. keepAlive:true, // 需要缓存
  29. title: '首页'
  30. }
  31. },
  32. {
  33. path: '/appmian',
  34. name:'主页',
  35. component: () => import('@/view/appmian.vue'),
  36. meta:{
  37. keepAlive:true, // 需要缓存
  38. title: '主页'
  39. }
  40. },
  41. {
  42. path: '/goods',
  43. name: 'goods',
  44. component: {
  45. // 这里的 goods 对应 router-view 中的 name
  46. goods: resultLeft
  47. }
  48. },
  49. {
  50. path: '/orderinfo',
  51. name: 'orderinfo',
  52. component: {
  53. // 这里的 orderinfo 对应 router-view 中的 name
  54. orderinfo:resultRight
  55. }
  56. }
  57. // {
  58. // path: '/resultLeft',
  59. // name:'resultLeft',
  60. // component: resultLeft,// 这是路由的籁加载,也可以其他方式
  61. // },
  62. // {
  63. // path: '/resultRight',
  64. // name:'resultRight',
  65. // components:{
  66. // resultRight:resultRight
  67. // } // 这是路由的籁加载,也可以其他方式
  68. // },
  69. ]
  70. })
  71. //修改动态网页标题 beforeEach 导航钩子,路由改变前触发
  72. router.beforeEach((to,from,next) =>{
  73. //window.document.title = to.meta.title;
  74. window.document.title = to.name;
  75. next();
  76. })
  77. router.afterEach((to,from,next) =>{
  78. window.scrollTo(0,0);
  79. })
  80. export default router;