fix: allow trailing slash in techdocs navigation

Signed-off-by: Laura Ceconi <laura.cec@hotmail.com>
This commit is contained in:
Laura Ceconi
2023-04-24 09:44:21 +02:00
parent f855ffe683
commit 863beb4949
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}`;