Skip to content

Commit

Permalink
fix: decode hash before selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 21, 2020
1 parent 7802cb5 commit e782c4c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e782c4c

Please sign in to comment.