From a7b3e22e69256e504475300791645c1ecf621d59 Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Thu, 6 Dec 2018 08:05:18 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20add=20router=20scroll=20behavio?= =?UTF-8?q?ur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@vuepress/core/lib/app/app.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/@vuepress/core/lib/app/app.js b/packages/@vuepress/core/lib/app/app.js index a56f88f5d8..b235cb1797 100644 --- a/packages/@vuepress/core/lib/app/app.js +++ b/packages/@vuepress/core/lib/app/app.js @@ -23,7 +23,7 @@ if (module.hot) { if (siteData.base !== prevBase) { window.alert( `[vuepress] Site base has changed. ` + - `Please restart dev server to ensure correct asset paths.` + `Please restart dev server to ensure correct asset paths.` ) } }) @@ -62,15 +62,25 @@ 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/ router.beforeEach((to, from, next) => { if (!/(\/|\.html)$/.test(to.path)) { - next(Object.assign({}, to, { - path: to.path + '/' - })) + next( + Object.assign({}, to, { + path: to.path + '/' + }) + ) } else { next() } @@ -94,7 +104,11 @@ export function createApp (isServer) { render (h) { return h('div', { attrs: { id: 'app' }}, [ h('router-view', { ref: 'layout' }), - h('div', { class: 'global-ui' }, globalUIComponents.map(component => h(component))) + h( + 'div', + { class: 'global-ui' }, + globalUIComponents.map(component => h(component)) + ) ]) } }) From 8de8f3e7e065117cddcbcde00123c3dfb47567bc Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Thu, 6 Dec 2018 08:06:04 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=94=A5=20remove=20smooth-scroll=20log?= =?UTF-8?q?ic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/app/root-mixins/updateLoadingState.js | 30 ------------------- 1 file changed, 30 deletions(-) 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() } } From a6c93ae989b41622f118c6a89bca4c89d0ba6b82 Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Thu, 6 Dec 2018 08:06:46 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9E=96=20remove=20smooth-scroll=20depend?= =?UTF-8?q?ency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@vuepress/core/package.json | 1 - yarn.lock | 4 ---- 2 files changed, 5 deletions(-) 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" From 285509565c5a02baac5147db049d911e293528a4 Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Fri, 7 Dec 2018 08:50:38 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=E2=8F=AA=20revert=20code=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@vuepress/core/lib/app/app.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/@vuepress/core/lib/app/app.js b/packages/@vuepress/core/lib/app/app.js index b235cb1797..ef21209478 100644 --- a/packages/@vuepress/core/lib/app/app.js +++ b/packages/@vuepress/core/lib/app/app.js @@ -23,7 +23,7 @@ if (module.hot) { if (siteData.base !== prevBase) { window.alert( `[vuepress] Site base has changed. ` + - `Please restart dev server to ensure correct asset paths.` + `Please restart dev server to ensure correct asset paths.` ) } }) @@ -76,11 +76,9 @@ export function createApp (isServer) { // redirect /foo to /foo/ router.beforeEach((to, from, next) => { if (!/(\/|\.html)$/.test(to.path)) { - next( - Object.assign({}, to, { - path: to.path + '/' - }) - ) + next(Object.assign({}, to, { + path: to.path + '/' + })) } else { next() } @@ -104,11 +102,7 @@ export function createApp (isServer) { render (h) { return h('div', { attrs: { id: 'app' }}, [ h('router-view', { ref: 'layout' }), - h( - 'div', - { class: 'global-ui' }, - globalUIComponents.map(component => h(component)) - ) + h('div', { class: 'global-ui' }, globalUIComponents.map(component => h(component))) ]) } })