From 863beb49498523db57e6109d4fbda29ba4e2bbe6 Mon Sep 17 00:00:00 2001 From: Laura Ceconi Date: Mon, 24 Apr 2023 09:44:21 +0200 Subject: [PATCH] fix: allow trailing slash in techdocs navigation Signed-off-by: Laura Ceconi --- .changeset/curvy-months-appear.md | 5 +++++ .../TechDocsReaderPageContent/useNavigateUrl.test.tsx | 6 ------ .../components/TechDocsReaderPageContent/useNavigateUrl.tsx | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 .changeset/curvy-months-appear.md diff --git a/.changeset/curvy-months-appear.md b/.changeset/curvy-months-appear.md new file mode 100644 index 0000000000..487e60c437 --- /dev/null +++ b/.changeset/curvy-months-appear.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs': patch +--- + +Re-add the possibility to have trailing slashes in Techdocs navigation. diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.test.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.test.tsx index 383ee4d688..b7d4c55ed7 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.test.tsx @@ -40,12 +40,6 @@ describe('resolveUrlToRelative', () => { const baseUrl = 'http://localhost:3000/instance'; expect(resolveUrlToRelative(url, baseUrl)).toBe('/test'); }); - - it('removes trailing slashes on the URL when present', () => { - const url = 'http://localhost:3000/test//'; - const baseUrl = 'http://localhost:3000'; - expect(resolveUrlToRelative(url, baseUrl)).toBe('/test'); - }); }); const Component = ({ to }: { to: string }) => { diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.tsx index dfe1058d75..02d181dccf 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/useNavigateUrl.tsx @@ -32,8 +32,7 @@ export function resolveUrlToRelative(url: string, baseUrl: string) { const relativeUrl = url .replace(appUrlPath, '') - // Remove any leading and trailing slashes. - .replace(/\/+$/, '') + // Remove any leading slashes. .replace(/^\/+/, ''); const parsedUrl = new URL(`http://localhost/${relativeUrl}`); return `${parsedUrl.pathname}${parsedUrl.search}${parsedUrl.hash}`;