-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,21 +62,7 @@ export function createApp (isServer) { | |
base: siteData.base, | ||
mode: 'history', | ||
fallback: false, | ||
routes, | ||
scrollBehavior: (to, from, saved) => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ulivz
Author
Member
|
||
if (saved) { | ||
return saved | ||
} else if (to.hash) { | ||
if (Vue.$vuepress.$get('disableScrollBehavior')) { | ||
return false | ||
} | ||
return { | ||
selector: to.hash | ||
} | ||
} else { | ||
return { x: 0, y: 0 } | ||
} | ||
} | ||
routes | ||
}) | ||
|
||
// redirect /foo to /foo/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js' | ||
|
||
export default { | ||
created () { | ||
this.$vuepress.$on('AsyncMarkdownContentMounted', () => { | ||
this.$vuepress.$set('contentMounted', true); | ||
this.$vuepress.$set('contentMounted', true) | ||
|
||
[].slice.call(document.querySelectorAll('a[href^="#"]')).forEach(anchor => { | ||
anchor.addEventListener('click', function (e) { | ||
e.preventDefault() | ||
history.pushState(history.state, document.title, e.target.href) | ||
window.scroll({ | ||
top: e.target.offsetTop - 75, | ||
left: 0, | ||
behavior: 'smooth' | ||
}) | ||
}) | ||
this.$smoothScroll = new SmoothScroll('a[href*="#"]', { | ||
speed: 1000, | ||
This comment has been minimized.
Sorry, something went wrong.
spiltcoffee
Contributor
|
||
easing: 'easeInOutCubic' | ||
}) | ||
|
||
if (this.$route.hash) { | ||
|
@@ -37,6 +32,11 @@ export default { | |
watch: { | ||
'$route.path' () { | ||
this.$vuepress.$set('contentMounted', false) | ||
this.$smoothScroll.destroy() | ||
} | ||
}, | ||
|
||
beforeDestroy () { | ||
this.$smoothScroll.destroy() | ||
} | ||
} |
@ulivz Was it intended to remove scrollBehavior completely? I now miss the scroll-to-top behavior when navigating between routes in the latest alpha.