mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-26 22:18:07 +00:00
fix(nuxt): use shared isChangingPage
util in scrollBehavior (#24091)
This commit is contained in:
parent
dc04f28cff
commit
d1306d6ebd
@ -2,6 +2,7 @@ import type { RouteLocationNormalized, RouterScrollBehavior } from '#vue-router'
|
|||||||
import { nextTick } from 'vue'
|
import { nextTick } from 'vue'
|
||||||
import type { RouterConfig } from 'nuxt/schema'
|
import type { RouterConfig } from 'nuxt/schema'
|
||||||
import { useNuxtApp } from '#app/nuxt'
|
import { useNuxtApp } from '#app/nuxt'
|
||||||
|
import { isChangingPage } from '#app/components/utils'
|
||||||
import { useRouter } from '#app/composables/router'
|
import { useRouter } from '#app/composables/router'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { appPageTransition as defaultPageTransition } from '#build/nuxt.config.mjs'
|
import { appPageTransition as defaultPageTransition } from '#build/nuxt.config.mjs'
|
||||||
@ -23,7 +24,7 @@ export default <RouterConfig> {
|
|||||||
const routeAllowsScrollToTop = typeof to.meta.scrollToTop === 'function' ? to.meta.scrollToTop(to, from) : to.meta.scrollToTop
|
const routeAllowsScrollToTop = typeof to.meta.scrollToTop === 'function' ? to.meta.scrollToTop(to, from) : to.meta.scrollToTop
|
||||||
|
|
||||||
// Scroll to top if route is changed by default
|
// Scroll to top if route is changed by default
|
||||||
if (!position && from && to && routeAllowsScrollToTop !== false && _isDifferentRoute(from, to)) {
|
if (!position && from && to && routeAllowsScrollToTop !== false && isChangingPage(to, from)) {
|
||||||
position = { left: 0, top: 0 }
|
position = { left: 0, top: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +62,3 @@ function _getHashElementScrollMarginTop (selector: string): number {
|
|||||||
} catch {}
|
} catch {}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function _isDifferentRoute (from: RouteLocationNormalized, to: RouteLocationNormalized): boolean {
|
|
||||||
return to.path !== from.path || JSON.stringify(from.params) !== JSON.stringify(to.params)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user