fix(nuxt): access resolved scrollBehaviorType (#22264)

This commit is contained in:
Daniel Roe 2023-07-21 10:17:07 +01:00 committed by GitHub
parent 9742bffac2
commit 429d3656e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ import type { RouteLocationNormalized, RouterScrollBehavior } from '#vue-router'
import { nextTick } from 'vue'
import type { RouterConfig } from 'nuxt/schema'
import { useNuxtApp } from '#app/nuxt'
import { useRouter } from '#app/composables/router'
// @ts-expect-error virtual file
import { appPageTransition as defaultPageTransition } from '#build/nuxt.config.mjs'
@ -12,7 +13,8 @@ type ScrollPosition = Awaited<ReturnType<RouterScrollBehavior>>
export default <RouterConfig> {
scrollBehavior (to, from, savedPosition) {
const nuxtApp = useNuxtApp()
const behavior = this.scrollBehaviorType ?? 'auto'
// @ts-expect-error untyped, nuxt-injected option
const behavior = useRouter().options?.scrollBehaviorType ?? 'auto'
// By default when the returned position is falsy or an empty object, vue-router will retain the current scroll position
// savedPosition is only available for popstate navigations (back button)