From aaaf59651e464828dcd7bf6b7a928e4859e5d1f2 Mon Sep 17 00:00:00 2001 From: Kiril Kartunov Date: Thu, 11 Mar 2021 11:29:17 +0200 Subject: [PATCH 1/2] implement #5424 --- src/shared/components/Contentful/Route.jsx | 31 ++++++++++++++++++++-- src/shared/routes/index.jsx | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/shared/components/Contentful/Route.jsx b/src/shared/components/Contentful/Route.jsx index 8085e1ccc0..8af288d58f 100644 --- a/src/shared/components/Contentful/Route.jsx +++ b/src/shared/components/Contentful/Route.jsx @@ -10,9 +10,10 @@ import LoadingIndicator from 'components/LoadingIndicator'; import MetaTags from 'components/MetaTags'; import PT from 'prop-types'; import React from 'react'; -import { Route, Switch } from 'react-router-dom'; +import { Route, Switch, Redirect } from 'react-router-dom'; import Viewport from 'components/Contentful/Viewport'; import PasswordScreen from 'components/Contentful/PasswordScreen'; +import { isomorphy } from 'topcoder-react-utils'; // Concatenates a base and segment and handles optional trailing slashes const buildUrl = (base, segment) => `${_.trimEnd(base, '/')}/${_.trim(segment, '/')}`; @@ -117,6 +118,29 @@ ChildRoutesLoader.propTypes = { url: PT.string.isRequired, }; +function RedirectWithStatus({ from, to, status }) { + return ( + { + if (to[0] !== '/' && isomorphy.isClientSide()) { + window.location.href = to; + return null; + } + // there is no `staticContext` on the client, so + // we need to guard against that here + if (staticContext) staticContext.status = status; + return ; + }} + /> + ); +} + +RedirectWithStatus.propTypes = { + from: PT.string.isRequired, + to: PT.string.isRequired, + status: PT.number.isRequired, +}; + export default function ContentfulRoute(props) { const { baseUrl, @@ -145,7 +169,10 @@ export default function ContentfulRoute(props) { render={(data) => { const { fields } = Object.values(data.entries.items)[0]; const url = path || buildUrl(baseUrl, fields.url); - return ( + const redirectToUrl = _.trim(fields.redirectToUrl); + return redirectToUrl ? ( + + ) : ( From e92c162a91de67c0dd5e9f0f0e3d3aa0be8bcd30 Mon Sep 17 00:00:00 2001 From: Kiril Kartunov Date: Thu, 11 Mar 2021 11:33:17 +0200 Subject: [PATCH 2/2] ci: on test --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4fe405c05b..06298a767c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -283,7 +283,7 @@ workflows: filters: branches: only: - - gigwork-updates + - route-redirects # This is alternate dev env for parallel testing - "build-qa": context : org-global