From 13f88468892923aa9ca61118024964af4ec8b346 Mon Sep 17 00:00:00 2001 From: blam Date: Sun, 7 Jun 2020 14:27:39 +0200 Subject: [PATCH] chore(react-router-v6): Fixing some more subrouting in the catalog page --- packages/core-api/src/app/App.tsx | 33 ++++--------------- .../ComponentPage/ComponentPage.tsx | 18 +++++----- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/packages/core-api/src/app/App.tsx b/packages/core-api/src/app/App.tsx index e47aa545ab..e9855e0a95 100644 --- a/packages/core-api/src/app/App.tsx +++ b/packages/core-api/src/app/App.tsx @@ -85,50 +85,31 @@ export class PrivateAppImpl implements BackstageApp { for (const output of plugin.output()) { switch (output.type) { case 'legacy-route': { - const { path, component: Component, options = {} } = output; - const { exact = true } = options; + const { path, component: Component } = output; routes.push( - } - exact={exact} - />, + } />, ); break; } case 'route': { - const { target, component: Component, options = {} } = output; - const { exact = true } = options; + const { target, component: Component } = output; routes.push( } - exact={exact} />, ); break; } case 'legacy-redirect-route': { - const { path, target, options = {} } = output; - const { exact = true } = options; - routes.push( - , - ); + const { path, target } = output; + routes.push(); break; } case 'redirect-route': { - const { from, to, options = {} } = output; - const { exact = true } = options; - routes.push( - , - ); + const { from, to } = output; + routes.push(); break; } case 'feature-flag': { diff --git a/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx b/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx index b9c89604b0..c0c0132d01 100644 --- a/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx +++ b/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx @@ -34,6 +34,7 @@ import { Grid } from '@material-ui/core'; import { catalogApiRef } from '../..'; import { entityToComponent } from '../../data/utils'; import { Component } from '../../data/component'; +import { useParams, useNavigate } from 'react-router'; const REDIRECT_DELAY = 1000; @@ -48,17 +49,19 @@ type ComponentPageProps = { }; }; -const ComponentPage: FC = ({ match, history }) => { +const ComponentPage: FC = () => { const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false); const [removingPending, setRemovingPending] = useState(false); const showRemovalDialog = () => setConfirmationDialogOpen(true); const hideRemovalDialog = () => setConfirmationDialogOpen(false); - const componentName = match.params.name; + const params = useParams() as { name: string }; + const componentName = params.name; + const navigate = useNavigate(); const errorApi = useApi(errorApiRef); const catalogApi = useApi(catalogApiRef); const { value: component, error, loading } = useAsync(async () => { - const entity = await catalogApi.getEntityByName(match.params.name); + const entity = await catalogApi.getEntityByName(params.name); const location = await catalogApi.getLocationByEntity(entity); return { ...entityToComponent(entity), location }; }); @@ -67,13 +70,13 @@ const ComponentPage: FC = ({ match, history }) => { if (error) { errorApi.post(new Error('Component not found!')); setTimeout(() => { - history.push('/'); + navigate('/'); }, REDIRECT_DELAY); } - }, [error, errorApi, history]); + }, [error, errorApi, navigate]); if (componentName === '') { - history.push('/catalog'); + navigate('/catalog'); return null; } @@ -83,7 +86,7 @@ const ComponentPage: FC = ({ match, history }) => { // await componentFactory.removeComponentByName(componentName); await catalogApi; - history.push('/'); + navigate('/'); }; // TODO - Replace with proper tabs implementation @@ -120,7 +123,6 @@ const ComponentPage: FC = ({ match, history }) => { - {confirmationDialogOpen && component && (