Skip to content

Commit f4a5193

Browse files
authored
Merge pull request #619 from topcoder-platform/TCA-1283_redirect-old-urls
TCA-1285 , TCA-1286 - redirect old urls to new ones -> dev
2 parents fed204e + 446fd68 commit f4a5193

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

src-ts/lib/route-provider/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './route-context-data.model'
44
export { default as routeContext } from './route.context'
55
export * from './route.provider'
66
export * from './router.utils'
7+
export * from './rewrite'

src-ts/lib/route-provider/rewrite.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { get } from 'lodash'
2+
import { FC } from 'react'
3+
import { Navigate, Params, useParams } from 'react-router-dom'
4+
5+
export interface RewriteProps {
6+
to: string
7+
}
8+
9+
/**
10+
* Extends react-router-dom Navigate component to support rewriting of urls
11+
* Eg. or rewrite rules:
12+
* - /learn/* -> /* (redirects all learn pages to root)
13+
*/
14+
export const Rewrite: FC<RewriteProps> = props => {
15+
const params: Params = useParams()
16+
const rewriteTo: string = props.to.replace(
17+
/(:[a-z0-9*]+)|\*/ig,
18+
(match: string) => get(params, match.replace(':', ''), ''),
19+
)
20+
21+
return (
22+
<Navigate to={rewriteTo} />
23+
)
24+
}

src-ts/tools/learn/learn.routes.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppSubdomain, EnvironmentConfig } from '../../config'
2-
import { authUrlLogin, lazyLoad, LazyLoadedComponent, PlatformRoute } from '../../lib'
2+
import { authUrlLogin, lazyLoad, LazyLoadedComponent, PlatformRoute, Rewrite } from '../../lib'
33

44
import { toolTitle } from './Learn'
55
import { LearnConfig } from './learn-config'
@@ -23,7 +23,7 @@ const MyCertificate: LazyLoadedComponent = lazyLoad(() => import('./course-certi
2323
const UserCertificate: LazyLoadedComponent = lazyLoad(() => import('./course-certificate'), 'UserCertificate')
2424
const FreeCodeCamp: LazyLoadedComponent = lazyLoad(() => import('./free-code-camp'), 'FreeCodeCamp')
2525
const MyLearning: LazyLoadedComponent = lazyLoad(() => import('./my-learning'), 'MyLearning')
26-
const LandingLearn: LazyLoadedComponent = lazyLoad(() => import('./Learn'))
26+
const LearnRootPage: LazyLoadedComponent = lazyLoad(() => import('./Learn'))
2727
const UserTCACertificate: LazyLoadedComponent = lazyLoad(() => import('./tca-certificate'), 'CertificateView')
2828

2929
const ValidateTCACertificate: LazyLoadedComponent
@@ -131,7 +131,7 @@ export function getTCACertificateUrl(
131131
export function getTCACertificationValidationUrl(
132132
completionUuid: string,
133133
): string {
134-
return `${absoluteRootRoute}/${completionUuid}`
134+
return `${absoluteRootRoute}/certificate/${completionUuid}`
135135
}
136136

137137
export function getTCAUserCertificationUrl(
@@ -151,6 +151,15 @@ export function getAuthenticateAndEnrollRoute(): string {
151151
return `${authUrlLogin()}${encodeURIComponent(LEARN_PATHS.tcaEnroll)}`
152152
}
153153

154+
const oldUrlRedirectRoute: ReadonlyArray<PlatformRoute> = EnvironmentConfig.SUBDOMAIN === AppSubdomain.tca ? [
155+
{
156+
children: [],
157+
element: <Rewrite to='/*' />,
158+
id: 'redirect-old-url',
159+
route: '/learn/*',
160+
},
161+
] : []
162+
154163
export const learnRoutes: ReadonlyArray<PlatformRoute> = [
155164
{
156165
children: [
@@ -225,7 +234,7 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
225234
children: [],
226235
element: <ValidateTCACertificate />,
227236
id: 'Hiring manager view - uuid param',
228-
route: ':completionUuid',
237+
route: 'certificate/:completionUuid',
229238
},
230239
{
231240
children: [],
@@ -239,9 +248,10 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
239248
id: 'Giring manager preview',
240249
route: 'tca-certifications/:certification/preview',
241250
},
251+
...oldUrlRedirectRoute,
242252
],
243253
domain: AppSubdomain.tca,
244-
element: <LandingLearn />,
254+
element: <LearnRootPage />,
245255
id: toolTitle,
246256
route: rootRoute,
247257
},

src-ts/tools/work/work.routes.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Navigate } from 'react-router-dom'
22

3-
import { contactSupportPath, lazyLoad, LazyLoadedComponent, PlatformRoute } from '../../lib'
3+
import { contactSupportPath, lazyLoad, LazyLoadedComponent, PlatformRoute, Rewrite } from '../../lib'
44
import { AppSubdomain, EnvironmentConfig } from '../../config'
55

66
import { dashboardRouteId, intakeFormsRouteId, toolTitle } from './Work'
@@ -49,6 +49,15 @@ export function workDetailRoute(workId: string, tab?: 'solutions' | 'messages'):
4949
return `${selfServiceRootRoute}/work-items/${workId}${!!tab ? `?tab=${tab}` : ''}`
5050
}
5151

52+
const oldUrlRedirectRoute: ReadonlyArray<PlatformRoute> = EnvironmentConfig.SUBDOMAIN === AppSubdomain.work ? [
53+
{
54+
children: [],
55+
element: <Rewrite to='/*' />,
56+
id: 'redirect-old-url',
57+
route: '/work/*',
58+
},
59+
] : []
60+
5261
export const workRoutes: ReadonlyArray<PlatformRoute> = [
5362
{
5463
element: <WorkNotLoggedIn />,
@@ -122,9 +131,14 @@ export const workRoutes: ReadonlyArray<PlatformRoute> = [
122131
element: <Navigate to={dashboardRoute} />,
123132
route: `${selfServiceRootRoute}/dashboard`,
124133
},
134+
{
135+
element: <Navigate to={selfServiceStartRoute} />,
136+
route: selfServiceRootRoute,
137+
},
125138
{
126139
children: [],
127140
element: <Navigate to={contactSupportPath} />,
128141
route: `${contactSupportPath}`,
129142
},
143+
...oldUrlRedirectRoute,
130144
]

0 commit comments

Comments
 (0)