) : (
diff --git a/lib/locale.ts b/lib/locale.ts
index 8cca476..0f84347 100644
--- a/lib/locale.ts
+++ b/lib/locale.ts
@@ -28,8 +28,12 @@ export function stripLocalePrefix(pathname: string): string {
return pathname || "/";
}
-export function getLocalizedPath(locale: string, pathname = "/"): string {
- return getLocalizedPathWithDefault(locale, pathname, routing.defaultLocale);
+export function getLocalizedPath(
+ locale: string,
+ pathname = "/",
+ defaultLocale: AppLocale = routing.defaultLocale,
+): string {
+ return getLocalizedPathWithDefault(locale, pathname, defaultLocale);
}
export function getLocalizedPathWithDefault(
diff --git a/middleware.ts b/middleware.ts
index 4d78d08..1c25008 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -196,9 +196,13 @@ export default async function middleware(request: NextRequest) {
configuredDefaultLocale !== routing.defaultLocale &&
!hasLocalePrefix(pathname)
) {
- const redirectUrl = request.nextUrl.clone();
- redirectUrl.pathname = getLocalizedPathWithDefault(configuredDefaultLocale, pathname, routing.defaultLocale);
- return NextResponse.redirect(redirectUrl, 307);
+ const rewriteUrl = request.nextUrl.clone();
+ rewriteUrl.pathname = getLocalizedPathWithDefault(
+ configuredDefaultLocale,
+ pathname,
+ routing.defaultLocale,
+ );
+ return NextResponse.rewrite(rewriteUrl);
}
if (