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}`;