Fix change lang with params in url
parent
c93a558e0c
commit
fbf5c3517e
|
@ -154,7 +154,7 @@ const App = () => {
|
|||
element={<Integration />}
|
||||
/>
|
||||
<Route
|
||||
path={relativeSitePaths.nouveautés + '/*'}
|
||||
path={relativeSitePaths.nouveautés.index + '/*'}
|
||||
element={<Nouveautés />}
|
||||
/>
|
||||
<Route path={relativeSitePaths.stats} element={<Stats />} />
|
||||
|
|
|
@ -22,12 +22,12 @@ export default function MoreInfosOnUs() {
|
|||
<>
|
||||
<H2>Plus d'infos sur mon-entreprise</H2>
|
||||
<Grid container spacing={2} role="list">
|
||||
{!pathname.startsWith(absoluteSitePaths.nouveautés) && (
|
||||
{!pathname.startsWith(absoluteSitePaths.nouveautés.index) && (
|
||||
<Grid item xs={12} sm={6} md={4} role="listitem">
|
||||
<SmallCard
|
||||
icon={<Emoji emoji={'✨'} />}
|
||||
title={<h3>Les nouveautés</h3>}
|
||||
to={absoluteSitePaths.nouveautés}
|
||||
to={absoluteSitePaths.nouveautés.index}
|
||||
>
|
||||
Qu'avons-nous mis en production ces derniers mois ?
|
||||
</SmallCard>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Helmet } from 'react-helmet-async'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { generatePath, matchPath, useLocation } from 'react-router-dom'
|
||||
import styled, { css } from 'styled-components'
|
||||
|
||||
import Contact from '@/components/Contact'
|
||||
|
@ -15,25 +15,43 @@ import { Container, Grid } from '@/design-system/layout'
|
|||
import { Link } from '@/design-system/typography/link'
|
||||
import { Body } from '@/design-system/typography/paragraphs'
|
||||
import { alternatePathname, useSitePaths } from '@/sitePaths'
|
||||
import { isNotNull } from '@/utils'
|
||||
|
||||
import InscriptionBetaTesteur from './InscriptionBetaTesteur'
|
||||
import Privacy from './Privacy'
|
||||
|
||||
const altPathname = alternatePathname()
|
||||
|
||||
const altPathnnamesWithParams = (
|
||||
lang: keyof typeof altPathname,
|
||||
path: string
|
||||
) =>
|
||||
Object.entries(altPathname[lang])
|
||||
.filter(([pth]) => /\/:/.test(pth))
|
||||
.map(([pth, alt]) => {
|
||||
const match = matchPath(pth, path)
|
||||
|
||||
return match && generatePath(alt, match.params)
|
||||
})
|
||||
.filter(isNotNull)
|
||||
|
||||
export default function Footer() {
|
||||
const { absoluteSitePaths } = useSitePaths()
|
||||
const { pathname } = useLocation()
|
||||
const { t, i18n } = useTranslation()
|
||||
const language = i18n.language as 'fr' | 'en'
|
||||
|
||||
const path = pathname.replace(/^\/(mon-entreprise|infrance)/, '')
|
||||
const path = decodeURIComponent(
|
||||
pathname.replace(/^\/(mon-entreprise|infrance)/, '')
|
||||
)
|
||||
const altLang = language === 'en' ? 'fr' : 'en'
|
||||
const altHref =
|
||||
(language === 'en'
|
||||
? import.meta.env.VITE_FR_BASE_URL
|
||||
: import.meta.env.VITE_EN_BASE_URL) + altPathname[language][path] ??
|
||||
altPathname[language][path + '/']
|
||||
: import.meta.env.VITE_EN_BASE_URL) +
|
||||
(altPathname[language][path] ??
|
||||
altPathnnamesWithParams(language, path)?.[0] ??
|
||||
'/')
|
||||
|
||||
const isFrenchMode = language === 'fr'
|
||||
|
||||
|
@ -96,7 +114,10 @@ export default function Footer() {
|
|||
</Link>
|
||||
</StyledLi>
|
||||
<StyledLi>
|
||||
<Link to={absoluteSitePaths.nouveautés} noUnderline>
|
||||
<Link
|
||||
to={absoluteSitePaths.nouveautés.index}
|
||||
noUnderline
|
||||
>
|
||||
Nouveautés <Emoji emoji="✨" />
|
||||
</Link>
|
||||
</StyledLi>
|
||||
|
|
|
@ -31,7 +31,7 @@ export const useFeedback = () => {
|
|||
// Exclure les pages et sous-pages
|
||||
![
|
||||
absoluteSitePaths.documentation.index,
|
||||
absoluteSitePaths.nouveautés,
|
||||
absoluteSitePaths.nouveautés.index,
|
||||
absoluteSitePaths.stats,
|
||||
absoluteSitePaths.développeur.index,
|
||||
].some((path) => currentPathDecoded.includes(path))
|
||||
|
|
|
@ -68,7 +68,7 @@ function NewsBanner({ lastRelease }: { lastRelease: LastRelease }) {
|
|||
<Body>
|
||||
Découvrez les nouveautés {determinant(lastRelease.name)}
|
||||
<Link
|
||||
to={absoluteSitePaths.nouveautés}
|
||||
to={absoluteSitePaths.nouveautés.index}
|
||||
aria-label={t(
|
||||
'Voir les nouveautés apportées par la version {{release}}',
|
||||
{ release: lastRelease.name.toLowerCase() }
|
||||
|
|
|
@ -47,7 +47,7 @@ export const PlanContent = () => {
|
|||
</Li>
|
||||
|
||||
<Li>
|
||||
<Link to={absoluteSitePaths.nouveautés}>
|
||||
<Link to={absoluteSitePaths.nouveautés.index}>
|
||||
<Trans>Nouveautés</Trans>
|
||||
</Link>
|
||||
</Li>
|
||||
|
|
|
@ -30,8 +30,8 @@ export default function Nouveautés() {
|
|||
const { data } = useFetchData<Releases>('/data/releases.json')
|
||||
const navigate = useNavigate()
|
||||
const { absoluteSitePaths } = useSitePaths()
|
||||
const slug = useMatch(`${encodeURI(absoluteSitePaths.nouveautés)}/:slug`)
|
||||
?.params?.slug
|
||||
const slug = useMatch(encodeURI(absoluteSitePaths.nouveautés.date))?.params
|
||||
?.date
|
||||
useHideNewsBanner()
|
||||
|
||||
const { t } = useTranslation()
|
||||
|
@ -48,7 +48,7 @@ export default function Nouveautés() {
|
|||
const selectedRelease = data.findIndex(({ name }) => slugify(name) === slug)
|
||||
|
||||
const getPath = (index: number) =>
|
||||
`${absoluteSitePaths.nouveautés}/${slugify(data[index].name)}`
|
||||
`${absoluteSitePaths.nouveautés.index}/${slugify(data[index].name)}`
|
||||
|
||||
if (!slug || selectedRelease === -1) {
|
||||
return <Navigate to={getPath(0)} replace />
|
||||
|
|
|
@ -87,7 +87,10 @@ const rawSitePathsFr = {
|
|||
is: 'impot-societe',
|
||||
dividendes: 'dividendes',
|
||||
},
|
||||
nouveautés: 'nouveautés',
|
||||
nouveautés: {
|
||||
index: 'nouveautés',
|
||||
date: ':date',
|
||||
},
|
||||
stats: 'statistiques',
|
||||
accessibilité: 'accessibilité',
|
||||
budget: 'budget',
|
||||
|
@ -173,7 +176,10 @@ const rawSitePathsEn = {
|
|||
is: 'corporate-tax',
|
||||
dividendes: 'dividends',
|
||||
},
|
||||
nouveautés: 'news',
|
||||
nouveautés: {
|
||||
index: 'news',
|
||||
date: ':date',
|
||||
},
|
||||
stats: 'statistics',
|
||||
accessibilité: 'accessibility',
|
||||
simulateursEtAssistants: 'simulators-and-assistants',
|
||||
|
@ -336,8 +342,6 @@ export const alternatePathname = () => {
|
|||
(acc, [key, path]): Return =>
|
||||
typeof path === 'object'
|
||||
? { ...acc, [key]: buildSitemap(lang, path, acc[key] as Return) }
|
||||
: /\/:/.test(path)
|
||||
? acc
|
||||
: ({ ...acc, [key]: { ...acc[key], [lang]: path } } as Return),
|
||||
initialValue
|
||||
)
|
||||
|
|
|
@ -259,3 +259,10 @@ export const catchDivideByZeroError = <T>(func: () => T) => {
|
|||
export const generateUuid = () => {
|
||||
return Math.floor(Math.random() * Date.now()).toString(16)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if x is not null, useful for filtering out nulls from arrays
|
||||
* @example [1, null, 2].filter(isNotNull) // [1, 2]
|
||||
* @param x
|
||||
*/
|
||||
export const isNotNull = <T>(x: T | null): x is T => x !== null
|
||||
|
|
Loading…
Reference in New Issue