fix: fix scrollBehavior

This commit is contained in:
Justineo 2021-10-18 18:52:29 +08:00
parent 85ef96d46b
commit fe6207cad0
No known key found for this signature in database
GPG Key ID: B73F0979CF18A0EA

View File

@ -1,23 +1,16 @@
export default function scrollBehavior (to) { export default function scrollBehavior (to) {
// if the returned position is falsy or an empty object, if (to.hash) {
// 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))
) {
// scroll to anchor by returning the selector // 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
} }