diff --git a/packages/@vuepress/core/lib/app/app.js b/packages/@vuepress/core/lib/app/app.js index a56f88f5d8..ef21209478 100644 --- a/packages/@vuepress/core/lib/app/app.js +++ b/packages/@vuepress/core/lib/app/app.js @@ -62,7 +62,15 @@ export function createApp (isServer) { base: siteData.base, mode: 'history', fallback: false, - routes + routes, + scrollBehavior (to, from, savedPosition) { + if (savedPosition) { + return savedPosition + } + if (to.path !== from.path) { + return { x: 0, y: 0 } + } + } }) // redirect /foo to /foo/ diff --git a/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js b/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js index 946f377064..7de5d9b272 100644 --- a/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js +++ b/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js @@ -1,43 +1,13 @@ -import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js' - export default { created () { this.$vuepress.$on('AsyncMarkdownContentMounted', () => { this.$vuepress.$set('contentMounted', true) - - this.$smoothScroll = new SmoothScroll('a[href*="#"]', { - speed: 1, - speedAsDuration: true, - easing: 'easeInOutCubic' - }) - - if (this.$route.hash) { - const hash = decodeURIComponent(this.$route.hash) - try { - const anchor = document.getElementById(hash.slice(1)) - const anchorLink = anchor.querySelector('a.header-anchor') - setTimeout(() => { - window.scroll({ - top: anchorLink.offsetTop - 70, - left: 0, - behavior: 'auto' - }) - }) - } catch (e) { - console.error(e) - } - } }) }, watch: { '$route.path' () { this.$vuepress.$set('contentMounted', false) - this.$smoothScroll.destroy() } - }, - - beforeDestroy () { - this.$smoothScroll.destroy() } } diff --git a/packages/@vuepress/core/package.json b/packages/@vuepress/core/package.json index 1e4b7e272b..8b964bc5cc 100644 --- a/packages/@vuepress/core/package.json +++ b/packages/@vuepress/core/package.json @@ -55,7 +55,6 @@ "optimize-css-assets-webpack-plugin": "^4.0.0", "portfinder": "^1.0.13", "postcss-loader": "^2.1.5", - "smooth-scroll": "^15.0.0", "toml": "^2.3.3", "url-loader": "^1.0.1", "vue": "^2.5.16", diff --git a/yarn.lock b/yarn.lock index 4e0e253b99..f0ced0be09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7606,10 +7606,6 @@ slice-ansi@1.0.0: dependencies: is-fullwidth-code-point "^2.0.0" -smooth-scroll@^15.0.0: - version "15.0.0" - resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-15.0.0.tgz#be4f9cb2cc4952d80db6736e5656ed5849305272" - snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"