From d5e7d778b6ce5ec018fa3306b27bf2a4fccdd35d Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Sat, 26 Feb 2022 17:48:49 +0800 Subject: [PATCH] fix(plugin-active-header-links): do not append hash when at top, close #693 --- .../src/client/composables/useActiveHeaderLinks.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/@vuepress/plugin-active-header-links/src/client/composables/useActiveHeaderLinks.ts b/packages/@vuepress/plugin-active-header-links/src/client/composables/useActiveHeaderLinks.ts index 472bd0a1e5..6bc5c459df 100644 --- a/packages/@vuepress/plugin-active-header-links/src/client/composables/useActiveHeaderLinks.ts +++ b/packages/@vuepress/plugin-active-header-links/src/client/composables/useActiveHeaderLinks.ts @@ -50,6 +50,17 @@ export const useActiveHeaderLinks = ({ document.body.scrollHeight ) + const isAtPageTop = scrollTop === 0 + + if (isAtPageTop) { + // make sure route hash is clean + replaceWithoutScrollBehavior(router, { + hash: '', + force: true, + }) + return + } + // check if we have reached page bottom // notice the `scrollBottom` might not be exactly equal to `scrollHeight`, so we add offset here const isAtPageBottom = Math.abs(scrollHeight - scrollBottom) < offset