diff --git a/src/components/FastNav.astro b/src/components/FastNav.astro index 40b2d6134..eaab2643a 100644 --- a/src/components/FastNav.astro +++ b/src/components/FastNav.astro @@ -23,6 +23,9 @@ var href = link.getAttribute('href'); if (!href || !href.startsWith('/docs')) return false; if (href === window.location.pathname) return false; + // Skip links with a hash — the swap scrolls to top, which would lose the + // anchor position. Full navigation handles the scroll-to-heading. + if (link.hash) return false; // Skip header tabs — they change the sidebar group if (link.closest('header') || link.closest('[role="tablist"]') || link.getAttribute('role') === 'tab') return false; // Skip if crossing between API layout and regular layout @@ -101,6 +104,7 @@ } function swapContent(html, href) { + var priorScroll = window.scrollY; var parser = new DOMParser(); var doc = parser.parseFromString(html, 'text/html'); @@ -129,6 +133,15 @@ oldSidebar.innerHTML = newSidebar.innerHTML; } + // Sync header tab highlight — intercepted links can cross tabs (e.g. the + // sidebar dropdown's Reference section links Docs/Cookbooks/SDK to each + // other), and nothing else swaps the header's active state + var newTabs = doc.querySelector('header nav[role="tablist"]'); + var oldTabs = document.querySelector('header nav[role="tablist"]'); + if (newTabs && oldTabs) { + oldTabs.innerHTML = newTabs.innerHTML; + } + // Re-execute inline scripts in swapped article // (innerHTML doesn't execute