diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index cfaf20aa07..63375c9565 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -28,6 +28,7 @@ All changes included in 1.6: ## `dashboard` Format +- ([#9411](https://github.com/quarto-dev/quarto-cli/issues/9411)): Fix issue with history navigation in dashboards and external links. - ([#10340](https://github.com/quarto-dev/quarto-cli/issues/10340)): Build card title correctly in the presence of equations and other markup. ## `html` Format diff --git a/src/resources/formats/dashboard/quarto-dashboard.js b/src/resources/formats/dashboard/quarto-dashboard.js index b24b74a08f..6b771b9bb7 100644 --- a/src/resources/formats/dashboard/quarto-dashboard.js +++ b/src/resources/formats/dashboard/quarto-dashboard.js @@ -145,8 +145,20 @@ window.document.addEventListener("DOMContentLoaded", function (_event) { const linkEls = document.querySelectorAll( ".quarto-dashboard-content a:not(.nav-link)" ); + const currentUrl = new URL(window.location.href); for (const linkEl of linkEls) { const linkHref = linkEl.getAttribute("href"); + // https://github.com/quarto-dev/quarto-cli/issues/9411 + // only add the event listener for internal links + try { + const linkUrl = new URL(linkHref); + if (linkUrl.origin !== currentUrl.origin) { + continue; + } + } catch (_e) { + // if the link is not a valid URL, skip it + continue; + } linkEl.addEventListener("click", () => { QuartoDashboardUtils.showPage(linkHref); return false;