fix: allow trailing slash in techdocs navigation
Signed-off-by: Laura Ceconi <laura.cec@hotmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs': patch
|
||||
---
|
||||
|
||||
Re-add the possibility to have trailing slashes in Techdocs navigation.
|
||||
-6
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user