From 39688c32d49e0ca402570175bd63daefa3823059 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Thu, 12 Oct 2023 14:38:47 +0200 Subject: [PATCH] Fix navigation to anchor Closes #1340. --- docs/.vuepress/enhanceApp.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/.vuepress/enhanceApp.js b/docs/.vuepress/enhanceApp.js index a1ba085603..63638e7984 100644 --- a/docs/.vuepress/enhanceApp.js +++ b/docs/.vuepress/enhanceApp.js @@ -50,23 +50,22 @@ export default ({ router }) => { // redirects redirects.forEach(route => router.addRoute(route)) - // initial page rendering - app.$once('hook:mounted', () => { - // temporary fix for https://github.com/vuejs/vuepress/issues/2428 - setTimeout(() => { - const { hash } = document.location - if (hash.length > 1) { - const id = hash.substring(1) - const element = document.getElementById(id) - if (element) element.scrollIntoView() - } - }, 500) - }) - document.addEventListener('click', handleClick) document.addEventListener('keyup', e => { if (isEnter(e)) handleClick(e) }) }) + + // temporary fix for https://github.com/vuejs/vuepress/issues/2428 + router.afterEach(to => { + const { hash } = to + if (hash.length > 1) { + setTimeout(() => { + const id = hash.substring(1) + const element = document.getElementById(id) + if (element) element.scrollIntoView() + }, 500) + } + }) } }