Skip to content

Commit

Permalink
fix: only add query string if there is one
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdubail committed Dec 12, 2024
1 parent 7ef872b commit 0515354
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/next/src/middlewares/appMidleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ export async function AppMiddleware(

if (isMultisiteRequest && !shouldRedirect) {
const hostNameOrSlug = site.slug || hostname;
const pagesRouterRewrite = `/_sites/${hostNameOrSlug}${pathname}`;
const queryString = searchParams.keys.length ? `?${searchParams.toString()}` : '';
const pagesRouterRewrite = `/_sites/${hostNameOrSlug}${pathname}${queryString}`;
const appRouterRewrite = locale
? `/${locale}/${hostNameOrSlug}${pathname.replace(`/${locale}`, '')}?${searchParams.toString()}`
: `/${hostNameOrSlug}${pathname}?${searchParams.toString()}`;
? `/${locale}/${hostNameOrSlug}${pathname.replace(`/${locale}`, '')}${queryString}`
: `/${hostNameOrSlug}${pathname}${queryString}`;

response = NextResponse.rewrite(
new URL(options.appRouter ? appRouterRewrite : pagesRouterRewrite, req.nextUrl),
Expand Down

0 comments on commit 0515354

Please sign in to comment.