chore: clear active toc className when change route

close #26541
This commit is contained in:
afc163 2020-09-07 15:43:56 +08:00
parent e678582012
commit 44f733ae23

View File

@ -58,12 +58,16 @@ function getSideBarOpenKeys(nextProps) {
return shouldOpenKeys;
}
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) {
[].forEach.call(document.querySelectorAll('.toc-affix li a'), node => {
node.className = '';
});
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