diff --git a/site/theme/template/Content/MainContent.jsx b/site/theme/template/Content/MainContent.jsx index dc514fbcc8..b16c2bd5e7 100644 --- a/site/theme/template/Content/MainContent.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -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