Merge pull request #17485 from lauraceconi/fix/techdocs-navigation

Allow trailing slash in Techdocs navigation
This commit is contained in:
Fredrik Adelöw
2023-04-24 15:47:20 +02:00
committed by GitHub
3 changed files with 6 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs': patch
---
Re-add the possibility to have trailing slashes in Techdocs navigation.
@@ -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 }) => {
@@ -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}`;