mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): use setTimeout
before scrolling when navigating (#25817)
This commit is contained in:
parent
6b504258bb
commit
0152cf48eb
@ -1,5 +1,4 @@
|
||||
import type { RouteLocationNormalized, RouterScrollBehavior } from '#vue-router'
|
||||
import { nextTick } from 'vue'
|
||||
import type { RouterConfig } from 'nuxt/schema'
|
||||
import { useNuxtApp } from '#app/nuxt'
|
||||
import { isChangingPage } from '#app/components/utils'
|
||||
@ -36,6 +35,8 @@ export default <RouterConfig> {
|
||||
if (to.hash) {
|
||||
return { el: to.hash, top: _getHashElementScrollMarginTop(to.hash), behavior }
|
||||
}
|
||||
// The route isn't changing so keep current scroll position
|
||||
return false
|
||||
}
|
||||
|
||||
// Wait for `page:transition:finish` or `page:finish` depending on if transitions are enabled or not
|
||||
@ -43,7 +44,7 @@ export default <RouterConfig> {
|
||||
const hookToWait = (hasTransition(from) && hasTransition(to)) ? 'page:transition:finish' : 'page:finish'
|
||||
return new Promise((resolve) => {
|
||||
nuxtApp.hooks.hookOnce(hookToWait, async () => {
|
||||
await nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
if (to.hash) {
|
||||
position = { el: to.hash, top: _getHashElementScrollMarginTop(to.hash), behavior }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user