mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-19 13:00:32 -05:00
* refactor(client): relocate to learn path tests file * refactor(client): add docs for to learn path Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> * fix: order imports Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
38 lines
966 B
TypeScript
38 lines
966 B
TypeScript
// This exists purely to redirect legacy challenge paths to /learn that could
|
|
// exist in the web (posts, url shares, etc).
|
|
|
|
import { Router, RouteComponentProps } from '@reach/router';
|
|
import { navigate, withPrefix } from 'gatsby';
|
|
import React from 'react';
|
|
|
|
import toLearnPath from '../utils/to-learn-path';
|
|
|
|
type RouteComponentPropsExtended = RouteComponentProps & {
|
|
block?: string;
|
|
challenge?: string;
|
|
superBlock?: string;
|
|
};
|
|
|
|
function Redirect(props: RouteComponentPropsExtended): null {
|
|
if (typeof window !== 'undefined') {
|
|
void navigate(toLearnPath(props));
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function Challenges(): JSX.Element {
|
|
return (
|
|
<Router basepath={withPrefix('/challenges')}>
|
|
<Redirect path='/:superBlock/' />
|
|
<Redirect path='/:superBlock/:block/' />
|
|
<Redirect path='/:superBlock/:block/:challenge' />
|
|
<Redirect default={true} />
|
|
</Router>
|
|
);
|
|
}
|
|
|
|
Challenges.displayName = 'Challenges';
|
|
|
|
export default Challenges;
|