Skip to content

Commit

Permalink
Fix navigation to anchor
Browse files Browse the repository at this point in the history
Closes #1340.
  • Loading branch information
dennisreimann committed Oct 12, 2023
1 parent cc1d93b commit 39688c3
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions docs/.vuepress/enhanceApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 39688c3

Please sign in to comment.