Merge pull request #28484 from jenil-harness/techdocs-fix

fix: Techdocs base url should be app.baseUrl
This commit is contained in:
John Philip
2025-01-20 03:25:07 -05:00
committed by GitHub
2 changed files with 11 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs': patch
---
Changed the base URL in addLinkClickListener from window.location.origin to app.baseUrl for improved path handling. This fixes an issue where Backstage, when running on a subpath, was unable to handle non-Backstage URLs of the same origin correctly.
@@ -20,7 +20,7 @@ import useMediaQuery from '@material-ui/core/useMediaQuery';
import { useTheme } from '@material-ui/core/styles';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { useAnalytics, useApi } from '@backstage/core-plugin-api';
import { configApiRef, useAnalytics, useApi } from '@backstage/core-plugin-api';
import { scmIntegrationsApiRef } from '@backstage/integration-react';
import {
@@ -68,6 +68,7 @@ export const useTechDocsReaderDom = (
const techdocsStorageApi = useApi(techdocsStorageApiRef);
const scmIntegrationsApi = useApi(scmIntegrationsApiRef);
const configApi = useApi(configApiRef);
const { state, path, content: rawPage } = useTechDocsReader();
const { '*': currPath = '' } = useParams();
@@ -193,7 +194,9 @@ export const useTechDocsReaderDom = (
scrollIntoNavigation(),
copyToClipboard(theme),
addLinkClickListener({
baseUrl: window.location.origin,
baseUrl:
configApi.getOptionalString('app.baseUrl') ||
window.location.origin,
onClick: (event: MouseEvent, url: string) => {
// detect if CTRL or META keys are pressed so that links can be opened in a new tab with `window.open`
const modifierActive = event.ctrlKey || event.metaKey;
@@ -258,7 +261,7 @@ export const useTechDocsReaderDom = (
onLoaded: () => {},
}),
]),
[theme, navigate, analytics, entityRef.name],
[theme, navigate, analytics, entityRef.name, configApi],
);
useEffect(() => {