diff --git a/site/source/components/App.tsx b/site/source/components/App.tsx index b8cc1f9d3..18c3610ef 100644 --- a/site/source/components/App.tsx +++ b/site/source/components/App.tsx @@ -3,7 +3,7 @@ import { FallbackRender } from '@sentry/react/types/errorboundary' import rules from 'modele-social' import { ComponentProps, StrictMode, useMemo } from 'react' import { useTranslation } from 'react-i18next' -import { Navigate, Route, Routes } from 'react-router-dom' +import { Route, Routes } from 'react-router-dom' import styled, { css } from 'styled-components' import Route404 from '@/components/Route404' @@ -37,6 +37,7 @@ import Integration from '@/pages/integration/index' import { useSitePaths } from '@/sitePaths' import Provider, { ProviderProps } from './Provider' +import Redirections from './Redirections' type RootProps = { basename: ProviderProps['basename'] @@ -71,51 +72,6 @@ export default function Root({ ) } -const Redirections = ({ children }: { children: React.ReactNode }) => { - const { absoluteSitePaths } = useSitePaths() - const redirections = [ - { - paths: ['/stats'], - to: absoluteSitePaths.stats, - }, - { - paths: ['/plan-de-site', '/site-map'], - to: absoluteSitePaths.plan, - }, - { - paths: [ - '/gérer/aide-declaration-independants/beta', - '/manage/declaration-aid-independent/beta', - ], - to: absoluteSitePaths.assistants.déclarationIndépendant.index, - }, - { - paths: [ - '/gérer/aide-declaration-independants', - '/manage/declaration-aid-independent', - ], - to: absoluteSitePaths.assistants[ - 'déclaration-charges-sociales-indépendant' - ], - }, - ] satisfies { paths: string[]; to: string }[] - - return ( - - {redirections.flatMap(({ paths, to }) => - paths.map((path) => ( - } - /> - )) - )} - - - ) -} - const Router = () => { const engine = useEngine() diff --git a/site/source/components/Redirections.tsx b/site/source/components/Redirections.tsx new file mode 100644 index 000000000..ee25fa4d0 --- /dev/null +++ b/site/source/components/Redirections.tsx @@ -0,0 +1,85 @@ +import { useMemo } from 'react' +import { Navigate, Route, Routes, useLocation } from 'react-router-dom' + +import { useSitePaths } from '@/sitePaths' + +interface Props { + children: React.ReactNode +} + +export default function Redirections({ children }: Props) { + const { absoluteSitePaths } = useSitePaths() + const { pathname } = useLocation() + + const redirections = useMemo(() => { + return [ + { + paths: ['/stats'], + to: absoluteSitePaths.stats, + }, + { + paths: ['/plan-de-site', '/site-map'], + to: absoluteSitePaths.plan, + }, + { + paths: [ + '/gérer/aide-declaration-independants/beta', + '/manage/declaration-aid-independent/beta', + ], + to: absoluteSitePaths.assistants.déclarationIndépendant.index, + }, + { + paths: [ + '/gérer/aide-declaration-independants', + '/manage/declaration-aid-independent', + ], + to: absoluteSitePaths.assistants[ + 'déclaration-charges-sociales-indépendant' + ], + }, + { + paths: [ + '/gérer/aide-declaration-independants', + '/manage/declaration-aid-independent', + ], + to: absoluteSitePaths.assistants[ + 'déclaration-charges-sociales-indépendant' + ], + }, + { + paths: ['/gérer/*', '/manage/*'], + to: decodeURI(pathname).replace( + /^\/(gérer|manage)/, + absoluteSitePaths.assistants.index + ), + }, + { + paths: ['/créer/*', '/create/*'], + to: decodeURI(pathname).replace( + /^\/(créer|create)/, + absoluteSitePaths.assistants['choix-du-statut'].index + ), + }, + ] satisfies { paths: string[]; to: string }[] + }, [ + absoluteSitePaths.assistants, + absoluteSitePaths.plan, + absoluteSitePaths.stats, + pathname, + ]) + + return ( + + {redirections.flatMap(({ paths, to }) => + paths.map((path) => ( + } + /> + )) + )} + + + ) +} diff --git a/site/source/pages/assistants/index.tsx b/site/source/pages/assistants/index.tsx index 6f5acb405..80f3f16bb 100644 --- a/site/source/pages/assistants/index.tsx +++ b/site/source/pages/assistants/index.tsx @@ -1,9 +1,8 @@ import { Trans } from 'react-i18next' -import { Route, Routes, useLocation } from 'react-router-dom' +import { Navigate, Route, Routes, useLocation } from 'react-router-dom' import { TrackChapter } from '@/components/ATInternetTracking' import PageData from '@/components/PageData' -import Route404 from '@/components/Route404' import { ScrollToTop } from '@/components/utils/Scroll' import { Link } from '@/design-system/typography/link' import useSimulatorsData from '@/hooks/useSimulatorsData' @@ -29,7 +28,13 @@ export default function Gérer() { - {/* } /> Navigate to /simu-et-assist */} + {/* TODO Navigate to /simu-et-assist */} + + } + /> ))} - } /> + + } + /> )