-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_middleware does not pass query params with getServerSideProps #35647
Comments
@samfromaway try the possible ways to fix approach from here please: https://nextjs.org/docs/messages/deleting-query-params-in-middlewares |
@MauriceArikoglu Thanks for the reply. Please read the issue fully. The error is NOT that I can't delete it. It's that the params don't pass. So the one-time error about "deleting-query-params-in-middlewares" that shows, is not what the issue is. I just mentioned it as it also appears. |
@samfromaway yes, I read and understand your problem. I hinted at the documentation, because it asks to use In your
If that doesn't help, I can't help you further |
@MauriceArikoglu |
Hey @samfromaway, that kinda makes sense (I think!). const newUrl = nextUrl.clone();
// newUrl.searchParams were cloned too
newUrl.pathname = `/_sites/${currentHost}${pathname}`; In context, your code will look like so: if (excludeCheck || pathname.includes(".html")) {
const hostname = req.headers.get("host");
const currentHost = process.env.DEV_ONLY_BRAND_URL || hostname;
const newUrl = req.nextUrl.clone();
newUrl.pathname = `/_sites/${currentHost}${pathname}`;
return NextResponse.rewrite(newUrl);
} I just checked it and it works well. Can you tell me if that's working out for you? 🙏 |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
chrome 99
How are you deploying your application? (if relevant)
No response
Describe the Bug
When using the _middleware with
return NextResponse.rewrite(
new URL(
/_sites/${currentHost}${pathname}
, req.url));
The query params are not getting passed in the pages using getServerSideProps.
Expected Behavior
Query params getting passed
To Reproduce
Use this repo: https://github.com/samfromaway/hostname-rewrites-param-issue
Run yarn dev
Go to: http://localhost:3000/booking?startDate=2022-04-14
See that only the site query param is passed, NOT the startDate or any other.
Copy code of file: this-middleware-does-work.ts in root to _middleware in /pages.
Then see that the params are actually passed.
The text was updated successfully, but these errors were encountered: