examples icon indicating copy to clipboard operation
examples copied to clipboard

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

Open StitiFatah opened this issue 4 years ago • 0 comments

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.

StitiFatah avatar Dec 08 '21 15:12 StitiFatah