mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
fix(nuxt): prevent initial scroll jump when loading page (#25483)
This commit is contained in:
parent
995acd9983
commit
ecc4c8e0c5
@ -78,13 +78,25 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
|
||||
startPosition = savedPosition
|
||||
return
|
||||
}
|
||||
// reset scroll behavior to initial value
|
||||
router.options.scrollBehavior = routerOptions.scrollBehavior
|
||||
return routerOptions.scrollBehavior?.(to, START_LOCATION, startPosition || savedPosition)
|
||||
if (routerOptions.scrollBehavior) {
|
||||
// reset scroll behavior to initial value
|
||||
router.options.scrollBehavior = routerOptions.scrollBehavior
|
||||
if ('scrollRestoration' in window.history) {
|
||||
const unsub = router.beforeEach(() => {
|
||||
unsub()
|
||||
window.history.scrollRestoration = 'manual'
|
||||
})
|
||||
}
|
||||
return routerOptions.scrollBehavior(to, START_LOCATION, startPosition || savedPosition)
|
||||
}
|
||||
},
|
||||
history,
|
||||
routes
|
||||
})
|
||||
|
||||
if (import.meta.client && 'scrollRestoration' in window.history) {
|
||||
window.history.scrollRestoration = 'auto'
|
||||
}
|
||||
nuxtApp.vueApp.use(router)
|
||||
|
||||
const previousRoute = shallowRef(router.currentRoute.value)
|
||||
|
Loading…
Reference in New Issue
Block a user