File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -33,14 +33,18 @@ export async function middleware(req: NextRequest) {
33
33
}
34
34
35
35
if ( req . nextUrl . locale === FAKE_LOCALE ) {
36
- // Apparently `localeDetection` does not work when using the faked locale
37
- // hack. So, detect the locale manually
36
+ // Apparently, the built-in `localeDetection`from Next does not work when
37
+ // using the faked locale hack. So, we need to detect the locale manually
38
38
const localeDetected = detectLocale ( req . headers . get ( "accept-language" ) )
39
39
const locale = localeDetected || DEFAULT_LOCALE
40
40
41
- return NextResponse . redirect (
42
- new URL ( `/${ locale } ${ req . nextUrl . pathname } ` , req . url ) ,
43
- { status : 301 }
44
- )
41
+ const redirectUrl = new URL ( `/${ locale } ${ req . nextUrl . pathname } ` , req . url )
42
+
43
+ // Add trailing slash if it's not present
44
+ if ( ! redirectUrl . pathname . endsWith ( "/" ) ) {
45
+ redirectUrl . pathname = redirectUrl . pathname + "/"
46
+ }
47
+
48
+ return NextResponse . redirect ( redirectUrl , { status : 301 } )
45
49
}
46
50
}
You can’t perform that action at this time.
0 commit comments