index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. // 其他路由将在对应页面组件创建后添加
  3. const routes = [
  4. {
  5. path: '/',
  6. name: 'Home',
  7. component: () => import('@/pages/home/Index.vue'),
  8. },
  9. {
  10. path: '/products',
  11. name: 'Products',
  12. component: () => import('@/pages/products/Index.vue'),
  13. },
  14. {
  15. path: '/cases',
  16. name: 'Cases',
  17. component: () => import('@/pages/cases/Index.vue'),
  18. },
  19. {
  20. path: '/casesdetails',
  21. name: 'Casesdetails',
  22. component: () => import('@/pages/casesdetails/Index.vue'),
  23. },
  24. {
  25. path: '/about',
  26. name: 'About',
  27. component: () => import('@/pages/about/Index.vue'),
  28. },
  29. {
  30. path: '/contact',
  31. name: 'Contact',
  32. component: () => import('@/pages/contact/Index.vue'),
  33. }
  34. ]
  35. const router = createRouter({
  36. history: createWebHistory(),
  37. routes,
  38. scrollBehavior(to, from, savedPosition) {
  39. // 如果有保存的位置(比如浏览器前进后退),则返回到保存的位置
  40. if (savedPosition) {
  41. return savedPosition
  42. }
  43. // 否则滚动到页面顶部
  44. return { top: 0 }
  45. }
  46. })
  47. export default router