路由滚动行为

50 阅读1分钟
function scrollBehavior(to: { hash: any }, from: any, savedPosition: any) {
  if (savedPosition) {
    return savedPosition
  }
  if (to.hash) {
    return { selector: to.hash }
  }
  return { x: 0, y: 0 }
}
const router = createRouter({
  history: createWebHistory(),
  routes,
  linkActiveClass: 'active',
  scrollBehavior,
})