Files
freeCodeCamp/client/src/pages/challenges.tsx
Victor Duarte 7c6524186e refactor(client): docs, ts and test challenges (#42978)
* 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>
2021-08-10 15:22:39 +02:00

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;