fix: decode hash before selecting

pull/59/head
Evan You 5 years ago
parent 7802cb55c2
commit e782c4cb86

@ -64,7 +64,7 @@ export function createRouter(
nextTick(() => {
if (targetLoc.hash && !scrollPosition) {
const target = document.querySelector(
targetLoc.hash
decodeURIComponent(targetLoc.hash)
) as HTMLElement
if (target) {
scrollTo(target, targetLoc.hash)
@ -150,7 +150,7 @@ function scrollTo(el: HTMLElement, hash: string, smooth = false) {
const pageOffset = document.getElementById('app')!.offsetTop
const target = el.classList.contains('.header-anchor')
? el
: document.querySelector(hash)
: document.querySelector(decodeURIComponent(hash))
if (target) {
const targetTop = (target as HTMLElement).offsetTop - pageOffset - 15
// only smooth scroll if distance is smaller than screen height.

Loading…
Cancel
Save