fix: fix scrollBehavior
This commit is contained in:
parent
85ef96d46b
commit
fe6207cad0
@ -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
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user