From 2d0d4db8a6e707cc8d786be31135bb98a959aa24 Mon Sep 17 00:00:00 2001 From: Benjamin Arias Date: Sat, 26 Nov 2022 10:41:25 +0100 Subject: [PATCH] =?UTF-8?q?Corrige=20le=20fonctionnement=20des=20liens=20d?= =?UTF-8?q?'=C3=A9vitement=20sur=20les=20pages=20autres=20que=20Landing=20?= =?UTF-8?q?(#2403)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Utilise * Revert "fix: Utilise " This reverts commit 872a90e039f8db446a43006671b676cd7d3065cb. * fix: Utilise url complète * fix: Ajoute rustine * chore: Ajoute commentaire --- site/source/App.tsx | 9 ++++---- site/source/components/layout/Header.tsx | 8 +++---- site/source/design-system/global-style.ts | 2 ++ site/source/hooks/useGetFullPath.ts | 20 ----------------- site/source/hooks/useGetFullURL.ts | 27 +++++++++++++++++++++++ site/source/pages/Landing/Landing.tsx | 8 +++---- 6 files changed, 41 insertions(+), 33 deletions(-) delete mode 100644 site/source/hooks/useGetFullPath.ts create mode 100644 site/source/hooks/useGetFullURL.ts diff --git a/site/source/App.tsx b/site/source/App.tsx index 0d25782d1..88efae51d 100644 --- a/site/source/App.tsx +++ b/site/source/App.tsx @@ -20,9 +20,8 @@ import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import { Container, Spacing } from '@/design-system/layout' import Provider, { ProviderProps } from './Provider' -import { Link } from './design-system/typography/link' import { useAxeCoreAnalysis } from './hooks/useAxeCoreAnalysis' -import { useGetFullPath } from './hooks/useGetFullPath' +import { useGetFullURL } from './hooks/useGetFullURL' import { useSaveAndRestoreScrollPosition } from './hooks/useSaveAndRestoreScrollPosition' import Accessibilité from './pages/Accessibilité' import Budget from './pages/Budget/Budget' @@ -99,7 +98,7 @@ const App = () => { const { t } = useTranslation() - const fullPath = useGetFullPath() + const fullURL = useGetFullURL() useSaveAndRestoreScrollPosition() const isEmbedded = useIsEmbedded() @@ -113,9 +112,9 @@ const App = () => { return ( {!isEmbedded &&
} - + {t('Passer le contenu')} - +
diff --git a/site/source/components/layout/Header.tsx b/site/source/components/layout/Header.tsx index acb4971fe..921e595bc 100644 --- a/site/source/components/layout/Header.tsx +++ b/site/source/components/layout/Header.tsx @@ -9,7 +9,7 @@ import { Container } from '@/design-system/layout' import { Switch } from '@/design-system/switch' import { Link } from '@/design-system/typography/link' import { useDarkMode } from '@/hooks/useDarkMode' -import { useGetFullPath } from '@/hooks/useGetFullPath' +import { useGetFullURL } from '@/hooks/useGetFullURL' import { useSitePaths } from '@/sitePaths' import NewsBanner from './NewsBanner' @@ -17,7 +17,7 @@ import NewsBanner from './NewsBanner' export default function Header() { const { absoluteSitePaths } = useSitePaths() - const fullPath = useGetFullPath() + const fullURL = useGetFullURL() const { i18n: { language }, @@ -28,9 +28,9 @@ export default function Header() { return (
- + {t('Aller au contenu')} - + { - const { i18n } = useTranslation() - const { pathname } = useLocation() - - const language = i18n.language as 'fr' | 'en' - - const pathStart = isDevelopment() ? DEVELOPMENT_BASE_PATHS[language] : '/' - - return `${pathStart}${pathname !== '/' ? pathname : ''}` -} diff --git a/site/source/hooks/useGetFullURL.ts b/site/source/hooks/useGetFullURL.ts new file mode 100644 index 000000000..18a49a09a --- /dev/null +++ b/site/source/hooks/useGetFullURL.ts @@ -0,0 +1,27 @@ +import { useEffect, useRef } from 'react' +import { useTranslation } from 'react-i18next' +import { useLocation } from 'react-router-dom' + +import { isDevelopment } from '../utils' + +const DEVELOPMENT_BASE_PATHS = { + fr: '/mon-entreprise', + en: '/infrance', +} + +export const useGetFullURL = () => { + const { i18n } = useTranslation() + const { pathname } = useLocation() + + const language = i18n.language as 'fr' | 'en' + + const pathStart = isDevelopment() ? DEVELOPMENT_BASE_PATHS[language] : '' + + // Rustine : permet d'utiliser window en SSR + const originRef = useRef('') + useEffect(() => { + originRef.current = window?.location?.origin || '' + }, []) + + return `${originRef.current}${pathStart}${pathname !== '/' ? pathname : ''}` +} diff --git a/site/source/pages/Landing/Landing.tsx b/site/source/pages/Landing/Landing.tsx index f06adb2c0..448dcb336 100644 --- a/site/source/pages/Landing/Landing.tsx +++ b/site/source/pages/Landing/Landing.tsx @@ -10,7 +10,7 @@ import { Container, Grid, Spacing } from '@/design-system/layout' import { H2 } from '@/design-system/typography/heading' import { Link } from '@/design-system/typography/link' import { Body, Intro } from '@/design-system/typography/paragraphs' -import { useGetFullPath } from '@/hooks/useGetFullPath' +import { useGetFullURL } from '@/hooks/useGetFullURL' import { useSitePaths } from '@/sitePaths' import { TrackPage } from '../../ATInternetTracking' @@ -25,7 +25,7 @@ export default function Landing() { const { absoluteSitePaths } = useSitePaths() const { t } = useTranslation() - const fullPath = useGetFullPath() + const fullURL = useGetFullURL() return ( <> @@ -37,9 +37,9 @@ export default function Landing() { ogImage="/logo-share.png" />
- + {t('Passer le contenu')} - +