Chore: Fix doc anchor bug (#16692)

pull/16704/head
iamkun 2019-07-23 17:59:47 +08:00 committed by Zhi Cun
parent 9ee2fedde7
commit e8483acb08
1 changed files with 6 additions and 3 deletions

View File

@ -240,11 +240,14 @@
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
next(); next();
setTimeout(() => { setTimeout(() => {
if (location.href.match(/#/g).length < 2) { const toPath = to.path;
const fromPath = from.path;
if (toPath === fromPath && to.hash) {
this.goAnchor();
}
if (toPath !== fromPath) {
document.documentElement.scrollTop = document.body.scrollTop = 0; document.documentElement.scrollTop = document.body.scrollTop = 0;
this.renderAnchorHref(); this.renderAnchorHref();
} else {
this.goAnchor();
} }
}, 100); }, 100);
} }