Reputation: 35760
In the pages router, you could create a getStaticProps
function, which would then feed props into your component function. getStaticProps
in turn got an argument of the request and response objects, so you could pass any information you wanted from them to your page.
In the app router, there is no longer a getStaticProps
function: you're just supposed to fetch your data from the component function. However, the component function doesn't get passed the request/response, so it seems impossible to access them now.
Is there some other mechanism to access the request/response objects in the latest version of Next.js?
Upvotes: 2
Views: 5188
Reputation: 35760
Based on jonrsharpe's comment, it looks like there no longer is a way to access the request from a page.
You can use an API route instead (which does get the full request), or you can use the headers
and cookies
functions (from the next/headers
package) to access just those parts of the request ... but it seems it's impossible to get any other information from the request, or to get the request object itself.
Upvotes: 2