Browse Source

chore: clear active toc className when change route

close #26541
pull/26721/head
afc163 4 years ago
parent
commit
44f733ae23
  1. 11
      site/theme/template/Content/MainContent.jsx

11
site/theme/template/Content/MainContent.jsx

@ -58,12 +58,16 @@ function getSideBarOpenKeys(nextProps) {
return shouldOpenKeys;
}
function updateActiveToc(id) {
const currentNode = document.querySelectorAll(`.toc-affix li a[href="#${id}"]`)[0];
if (currentNode) {
function clearActiveToc() {
[].forEach.call(document.querySelectorAll('.toc-affix li a'), node => {
node.className = '';
});
}
function updateActiveToc(id) {
const currentNode = document.querySelectorAll(`.toc-affix li a[href="#${id}"]`)[0];
if (currentNode) {
clearActiveToc();
currentNode.className = 'current';
}
}
@ -97,6 +101,7 @@ class MainContent extends Component {
this.bindScroller();
}
if (!window.location.hash && prevLocation.pathname !== location.pathname) {
clearActiveToc();
window.scrollTo(0, 0);
}
// when subMenu not equal

Loading…
Cancel
Save