diff --git a/packages/nuxt/src/pages/runtime/composables.ts b/packages/nuxt/src/pages/runtime/composables.ts index ca977dd23ed..6c517be0443 100644 --- a/packages/nuxt/src/pages/runtime/composables.ts +++ b/packages/nuxt/src/pages/runtime/composables.ts @@ -29,6 +29,8 @@ export interface PageMeta { layoutTransition?: boolean | TransitionProps key?: false | string | ((route: RouteLocationNormalizedLoaded) => string) keepalive?: boolean | KeepAliveProps + /** Set to `false` to avoid scrolling to top on page navigations */ + scrollToTop?: boolean } declare module 'vue-router' { diff --git a/packages/nuxt/src/pages/runtime/router.options.ts b/packages/nuxt/src/pages/runtime/router.options.ts index 7d2f6ed2876..1137b346dde 100644 --- a/packages/nuxt/src/pages/runtime/router.options.ts +++ b/packages/nuxt/src/pages/runtime/router.options.ts @@ -16,7 +16,11 @@ export default { let position: ScrollPosition = savedPosition || undefined // Scroll to top if route is changed by default - if (!position && from.matched[0] !== to.matched[0]) { + if ( + !position && + (from && to && from.matched[0] !== to.matched[0]) && + to.meta.scrollToTop !== false + ) { position = { left: 0, top: 0 } }