1
1
import { setContext , setTags } from '@sentry/nextjs' ;
2
- import { notFound } from 'next/navigation' ;
2
+ import { notFound , redirect } from 'next/navigation' ;
3
3
import { unstable_setRequestLocale } from 'next-intl/server' ;
4
4
import type { FC } from 'react' ;
5
5
@@ -9,7 +9,11 @@ import WithLayout from '@/components/withLayout';
9
9
import { ENABLE_STATIC_EXPORT , VERCEL_REVALIDATE } from '@/next.constants.mjs' ;
10
10
import { PAGE_VIEWPORT , DYNAMIC_ROUTES } from '@/next.dynamic.constants.mjs' ;
11
11
import { 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' ;
13
17
import { MatterProvider } from '@/providers/matterProvider' ;
14
18
15
19
type DynamicStaticPaths = { path : Array < string > ; locale : string } ;
@@ -67,7 +71,14 @@ const getPage: FC<DynamicParams> = async ({ params }) => {
67
71
// Forces the current locale to be the Default Locale
68
72
unstable_setRequestLocale ( defaultLocale . code ) ;
69
73
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 } ` ) ;
71
82
}
72
83
73
84
// Configures the current Locale to be the given Locale of the Request
0 commit comments