Skip to content
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

Is it possible to get query paramaters with useRouter() when rewriting with _middleware.ts ? #58

Closed
StitiFatah opened this issue Dec 8, 2021 · 1 comment

Comments

@StitiFatah
Copy link

StitiFatah commented Dec 8, 2021

When rewriting through next.config.js as explained here https://nextjs.org/docs/api-reference/next.config.js/rewrites it was possible to get query parameters from useRouter().query but when using rewrites via _middleware.ts with NextResponse.rewrite(path) as shown in this example https://github.com/vercel/examples/blob/main/edge-functions/hostname-rewrites/pages/_middleware.ts useRouter().query is an empty object.

Or is the only way to access paramters from context.params using getStaticProps or getServerSideProps ?

Thanks.

Edit : Seems related to #55 , when I export getStaticProps or getServerSideProps, even without returning context.params useRouter().query is populated but if not I got the error described there and an empty object.

@lfades
Copy link
Member

lfades commented Jan 24, 2023

I'm quite late but:

Or is the only way to access paramters from context.params using getStaticProps or getServerSideProps ?

Yes, that's the only way as in those two scenarios because the query object data isn't coming from the browser but from the build (getStaticProps) or the incoming request (getServerSideProps), if the page is static then there's no way to know about dynamic params before hydration (meaning you can only know the query params after the initial render)

@lfades lfades closed this as completed Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants