Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
support scrollToTop page meta
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 19, 2022
1 parent 3ec9051 commit 023936f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/nuxt/src/pages/runtime/composables.ts
Expand Up @@ -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' {
Expand Down
6 changes: 5 additions & 1 deletion packages/nuxt/src/pages/runtime/router.options.ts
Expand Up @@ -16,7 +16,11 @@ export default <RouterConfig> {
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 }
}

Expand Down

0 comments on commit 023936f

Please sign in to comment.