From 429d3656e9ffc16b6a0d3b4797c0c97bd0e4b5b5 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 21 Jul 2023 10:17:07 +0100 Subject: [PATCH] fix(nuxt): access resolved `scrollBehaviorType` (#22264) --- packages/nuxt/src/pages/runtime/router.options.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/pages/runtime/router.options.ts b/packages/nuxt/src/pages/runtime/router.options.ts index 1a8875f3c2..d5c8bdbb59 100644 --- a/packages/nuxt/src/pages/runtime/router.options.ts +++ b/packages/nuxt/src/pages/runtime/router.options.ts @@ -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> export default { 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)