11import { setContext , setTags } from '@sentry/nextjs' ;
2- import { notFound } from 'next/navigation' ;
2+ import { notFound , redirect } from 'next/navigation' ;
33import { unstable_setRequestLocale } from 'next-intl/server' ;
44import type { FC } from 'react' ;
55
@@ -9,7 +9,11 @@ import WithLayout from '@/components/withLayout';
99import { ENABLE_STATIC_EXPORT , VERCEL_REVALIDATE } from '@/next.constants.mjs' ;
1010import { PAGE_VIEWPORT , DYNAMIC_ROUTES } from '@/next.dynamic.constants.mjs' ;
1111import { dynamicRouter } from '@/next.dynamic.mjs' ;
12- import { availableLocaleCodes , defaultLocale } from '@/next.locales.mjs' ;
12+ import {
13+ allLocaleCodes ,
14+ availableLocaleCodes ,
15+ defaultLocale ,
16+ } from '@/next.locales.mjs' ;
1317import { MatterProvider } from '@/providers/matterProvider' ;
1418
1519type DynamicStaticPaths = { path : Array < string > ; locale : string } ;
@@ -67,7 +71,14 @@ const getPage: FC<DynamicParams> = async ({ params }) => {
6771 // Forces the current locale to be the Default Locale
6872 unstable_setRequestLocale ( defaultLocale . code ) ;
6973
70- return notFound ( ) ;
74+ if ( ! allLocaleCodes . includes ( locale ) ) {
75+ // when the locale is not listed in the locales, return NotFound
76+ return notFound ( ) ;
77+ }
78+
79+ // Redirect to the default locale path
80+ const pathname = dynamicRouter . getPathname ( path ) ;
81+ return redirect ( `/${ defaultLocale . code } /${ pathname } ` ) ;
7182 }
7283
7384 // Configures the current Locale to be the given Locale of the Request
0 commit comments