Skip to content

Commit c47decb

Browse files
authored
Merge pull request #1636 from IFRCGo/feature/redirect-obsolete-urls
Redirect obsolete URLs
2 parents 32b26e6 + c5f59ce commit c47decb

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

.changeset/thirty-beans-beam.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
Redirect obsolete URLs to recent ones
6+
- reports/999 -> field-reports/999
7+
- deployments -> surge/overview

app/src/App/routes/SurgeRoutes.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,23 @@ const deploymentCatalogueChildren = customWrapRoute({
14431443
},
14441444
});
14451445

1446+
const obsoleteUrlDeployments = customWrapRoute({
1447+
parent: rootLayout,
1448+
path: 'deployments',
1449+
component: {
1450+
eagerLoad: true,
1451+
render: Navigate,
1452+
props: {
1453+
to: surgeOverview.absolutePath,
1454+
},
1455+
},
1456+
wrapperComponent: Auth,
1457+
context: {
1458+
title: 'Surge Overview',
1459+
visibility: 'anything',
1460+
},
1461+
});
1462+
14461463
export default {
14471464
surgeLayout,
14481465
surgeOverview,
@@ -1537,4 +1554,5 @@ export default {
15371554
deploymentCatalogueIndex,
15381555
deploymentCatalogueChildren,
15391556
deploymentOthers,
1557+
obsoleteUrlDeployments,
15401558
};

app/src/App/routes/index.tsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { Navigate } from 'react-router-dom';
1+
import {
2+
generatePath,
3+
Navigate,
4+
useParams,
5+
} from 'react-router-dom';
26

37
import { unwrapRoute } from '#utils/routes';
48

@@ -1187,6 +1191,40 @@ const preparednessOperationalLearning = customWrapRoute({
11871191
},
11881192
});
11891193

1194+
// eslint-disable-next-line react-refresh/only-export-components
1195+
function ObsoleteFieldReportRedirection() {
1196+
const params = useParams<{
1197+
fieldReportId: string,
1198+
}>();
1199+
1200+
const path = generatePath(
1201+
fieldReportDetails.absoluteForwardPath,
1202+
{ fieldReportId: params.fieldReportId },
1203+
);
1204+
1205+
return (
1206+
<Navigate
1207+
to={path}
1208+
replace
1209+
/>
1210+
);
1211+
}
1212+
1213+
const obsoleteFieldReportDetails = customWrapRoute({
1214+
parent: rootLayout,
1215+
path: 'reports/:fieldReportId',
1216+
component: {
1217+
eagerLoad: true,
1218+
render: ObsoleteFieldReportRedirection,
1219+
props: {},
1220+
},
1221+
wrapperComponent: Auth,
1222+
context: {
1223+
title: 'Field Report Details',
1224+
visibility: 'anything',
1225+
},
1226+
});
1227+
11901228
const wrappedRoutes = {
11911229
fourHundredFour,
11921230
rootLayout,
@@ -1273,6 +1311,7 @@ const wrappedRoutes = {
12731311

12741312
// Redirects
12751313
preparednessOperationalLearning,
1314+
obsoleteFieldReportDetails,
12761315
};
12771316

12781317
export const unwrappedRoutes = unwrapRoute(Object.values(wrappedRoutes));

0 commit comments

Comments
 (0)