reset and modify.

This commit is contained in:
vagra 2020-04-27 16:55:55 +08:00
parent 2623b94dd3
commit b108c86d38
2 changed files with 8 additions and 4 deletions

View File

@ -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', () => {

View File

@ -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;