Skip to content

Commit

Permalink
Fix tab heading anchors for “history” routerMode
Browse files Browse the repository at this point in the history
Fix #34
Fix #55
  • Loading branch information
jhildenbiddle committed Apr 16, 2024
1 parent c2a6dcf commit ed2010a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ function setActiveTab(elm, _isMatchingTabSync = false) {
* Sets the active tab based on the anchor ID in the URL
*/
function setActiveTabFromAnchor() {
const anchorID = decodeURIComponent((window.location.hash.match(/(?:id=)([^&]+)/) || [])[1]);
const uriComponent = window.location.hash || window.location.search;
const anchorID = decodeURIComponent((uriComponent.match(/(?:id=)([^&]+)/) || [])[1]);
const anchorSelector = anchorID && `.${classNames.tabBlock} #${anchorID}`;
const isAnchorElmInTabBlock = anchorID && document.querySelector(anchorSelector);

Expand Down Expand Up @@ -398,8 +399,6 @@ function docsifyTabs(hook, vm) {
tabsContainer.addEventListener('click', function handleTabClick(evt) {
setActiveTab(evt.target);
});

window.addEventListener('hashchange', setActiveTabFromAnchor, false);
});
}

Expand Down

0 comments on commit ed2010a

Please sign in to comment.