From fe6207cad053c0c1171e570769ad61203aa1338d Mon Sep 17 00:00:00 2001 From: Justineo Date: Mon, 18 Oct 2021 18:52:29 +0800 Subject: [PATCH] fix: fix scrollBehavior --- app/router.scrollBehavior.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/app/router.scrollBehavior.js b/app/router.scrollBehavior.js index 9947943..7e4298a 100644 --- a/app/router.scrollBehavior.js +++ b/app/router.scrollBehavior.js @@ -1,23 +1,16 @@ export default function scrollBehavior (to) { - // if the returned position is falsy or an empty object, - // will retain current scroll position. - let position = false - - // if no children detected - if (to.matched.length < 2) { - // scroll to the top of the page - position = { x: 0, y: 0 } - } else if ( - to.matched.some(r => r.components.default.options.scrollToTop) - ) { - // if one of the children has scrollToTop option set to true - position = { x: 0, y: 0 } - } else if ( - to.hash && - document.querySelector(decodeURIComponent(to.hash)) - ) { + if (to.hash) { // scroll to anchor by returning the selector - position = { selector: to.hash } + return { + selector: decodeURIComponent(to.hash), + offset: { + y: 20 + } + } + } + + return { + x: 0, + y: 0 } - return position }