diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index ef78443ba..47d64b417 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -1,5 +1,6 @@ import { isMobile } from '../util/env'; import * as dom from '../util/dom'; +import { removeParams } from '../router/util'; import config from '../config'; import Tweezer from 'tweezer.js'; @@ -59,8 +60,7 @@ function highlight(path) { return; } - const li = - nav[getNavKey(decodeURIComponent(path), last.getAttribute('data-id'))]; + const li = nav[getNavKey(path, last.getAttribute('data-id'))]; if (!li || li === active) { return; @@ -86,7 +86,7 @@ function highlight(path) { } function getNavKey(path, id) { - return `${path}?id=${id}`; + return `${decodeURIComponent(path)}?id=${decodeURIComponent(id)}`; } export function scrollActiveSidebar(router) { @@ -127,7 +127,7 @@ export function scrollActiveSidebar(router) { return; } - const path = router.getCurrentPath(); + const path = removeParams(router.getCurrentPath()); dom.off('scroll', () => highlight(path)); dom.on('scroll', () => highlight(path)); dom.on(sidebar, 'mouseover', () => { diff --git a/src/core/router/util.js b/src/core/router/util.js index ba2eed8a1..fc3e2f79d 100644 --- a/src/core/router/util.js +++ b/src/core/router/util.js @@ -44,6 +44,10 @@ export const isAbsolutePath = cached(path => { return /(:|(\/{2}))/g.test(path); }); +export const removeParams = cached(path => { + return path.split(/[?#]/)[0]; +}); + export const getParentPath = cached(path => { if (/\/$/g.test(path)) { return path;