From 3a1a999b7beb446b152062d721c87ebb469523ed Mon Sep 17 00:00:00 2001 From: Phil Kuang Date: Thu, 13 Oct 2022 11:33:17 -0400 Subject: [PATCH] fix(techdocsReader): include search params when navigating urls Signed-off-by: Phil Kuang --- .changeset/spicy-parents-lick.md | 5 +++++ .../reader/components/TechDocsReaderPageContent/dom.tsx | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/spicy-parents-lick.md diff --git a/.changeset/spicy-parents-lick.md b/.changeset/spicy-parents-lick.md new file mode 100644 index 0000000000..692745ed12 --- /dev/null +++ b/.changeset/spicy-parents-lick.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs': patch +--- + +Include query parameters when navigating to relative links in documents diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx index 0e811af6e0..e886454594 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx @@ -175,13 +175,14 @@ export const useTechDocsReaderDom = ( // detect if CTRL or META keys are pressed so that links can be opened in a new tab with `window.open` const modifierActive = event.ctrlKey || event.metaKey; const parsedUrl = new URL(url); + const fullPath = `${parsedUrl.pathname}${parsedUrl.search}${parsedUrl.hash}`; // hash exists when anchor is clicked on secondary sidebar if (parsedUrl.hash) { if (modifierActive) { - window.open(`${parsedUrl.pathname}${parsedUrl.hash}`, '_blank'); + window.open(fullPath, '_blank'); } else { - navigate(`${parsedUrl.pathname}${parsedUrl.hash}`); + navigate(fullPath); // Scroll to hash if it's on the current page transformedElement ?.querySelector(`[id="${parsedUrl.hash.slice(1)}"]`) @@ -189,9 +190,9 @@ export const useTechDocsReaderDom = ( } } else { if (modifierActive) { - window.open(parsedUrl.pathname, '_blank'); + window.open(fullPath, '_blank'); } else { - navigate(parsedUrl.pathname); + navigate(fullPath); } } },