-
Notifications
You must be signed in to change notification settings - Fork 958
Description
When accessing a subdomain route such as
http://domain.localhost:3001/thank-you?card_id=order_XXXXXXX
the middleware rewrites the path to /s/vibees-sarma/thank-you, but the query parameters (e.g., card_id) are not preserved in the rewritten request. As a result, searchParams in the corresponding page component is always empty.
Steps to Reproduce:
Visit a subdomain route with query parameters, e.g.
http://domain.localhost:3001/thank-you?card_id=order_XXXXXXXX
The middleware rewrites the path to /s/vibees-sarma/thank-you.
In the page component, props.searchParams is {}.
Expected Behavior:
The query parameters should be preserved after the rewrite, so props.searchParams contains the expected values.
Actual Behavior:
props.searchParams is always empty after the rewrite.
Relevant Code:
// middleware.ts excerpt
if (subdomain) {
// For other paths on subdomain (like /thank-you)
const url = new URL(request.url);
url.pathname = `/s/${subdomain}${pathname}`;
return NextResponse.rewrite(url);
}
Suggested Fix:
Ensure that the rewritten URL preserves the original query parameters by constructing the new URL using the original request.url and only changing the pathname. This way, the query string is retained and available in the page component.