import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('@/views/HomeViewNew.vue'),
    },
    {
      path: '/legacy',
      name: 'HomeLegacy',
      component: () => import('@/views/HomeView.vue'),
    },
  ],
  scrollBehavior(to, _from, savedPosition) {
    if (savedPosition) return savedPosition
    if (to.hash) {
      return { el: to.hash, behavior: 'smooth', top: 80 }
    }
    // 用 instant 避免与浏览器默认行为、异步挂载 DOM 抢滚动，出现「先顶再被拉到锚点/底部」
    return { top: 0, left: 0, behavior: 'auto' }
  },
})

export default router
