File tree 2 files changed +9
-1
lines changed
2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' nextra-theme-docs ' : patch
3
+ ' nextra ' : patch
4
+ ---
5
+
6
+ Fix ` nextra/locales ` middleware, redirect to the docs URL relative to the ` /<basePath> ` .
Original file line number Diff line number Diff line change 1
1
import { match as matchLocale } from '@formatjs/intl-localematcher'
2
2
import Negotiator from 'negotiator'
3
+ import { addBasePath } from 'next/dist/client/add-base-path'
3
4
import { NextResponse } from 'next/server'
4
5
import type { NextRequest } from 'next/server'
5
6
@@ -35,9 +36,10 @@ export function middleware(request: NextRequest) {
35
36
if ( ! pathnameHasLocale ) {
36
37
const locale = cookieLocale || getHeadersLocale ( request )
37
38
39
+ const url = addBasePath ( `/${ locale } ${ pathname } ` )
38
40
// e.g. incoming request is /products
39
41
// The new URL is now /en-US/products
40
- return NextResponse . redirect ( new URL ( `/ ${ locale } ${ pathname } ` , request . url ) )
42
+ return NextResponse . redirect ( new URL ( url , request . url ) )
41
43
}
42
44
43
45
const requestLocale = pathname . split ( '/' , 2 ) [ 1 ]
You can’t perform that action at this time.
0 commit comments