From e8483acb08301ad11beecc4e244a83f01e61b1bd Mon Sep 17 00:00:00 2001 From: iamkun Date: Tue, 23 Jul 2019 17:59:47 +0800 Subject: [PATCH] Chore: Fix doc anchor bug (#16692) --- examples/pages/template/component.tpl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/pages/template/component.tpl b/examples/pages/template/component.tpl index b3c0474db..a2c8721aa 100644 --- a/examples/pages/template/component.tpl +++ b/examples/pages/template/component.tpl @@ -240,11 +240,14 @@ beforeRouteUpdate(to, from, next) { next(); 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; this.renderAnchorHref(); - } else { - this.goAnchor(); } }, 100); }