Skip to content

Commit a623845

Browse files
committed
test: adjust fixture to use NextUrl to preserve locale when rewriting
1 parent f0d47c1 commit a623845

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/fixtures/middleware-i18n/middleware.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { NextResponse } from 'next/server'
22

3+
/**
4+
* @param {import('next/server').NextRequest} request
5+
*/
36
export async function middleware(request) {
47
const url = request.nextUrl
58

@@ -17,11 +20,9 @@ export async function middleware(request) {
1720
}
1821

1922
if (url.pathname.startsWith('/link/rewrite-me')) {
20-
const rewriteUrl = new URL(
21-
url.pathname.replace('/link/rewrite-me', '/link/rewrite-target'),
22-
url,
23-
)
24-
return NextResponse.rewrite(rewriteUrl, {
23+
// use NextUrl to rewrite the URL as it does preserve the locale
24+
url.pathname = url.pathname.replace('/link/rewrite-me', '/link/rewrite-target')
25+
return NextResponse.rewrite(url, {
2526
headers: {
2627
'x-middleware-test': 'link-rewrite',
2728
},

0 commit comments

Comments
 (0)