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

Loading…
Cancel
Save