next.js
next.js copied to clipboard
Access Request Object in New App Directory Page Route
Describe the feature you'd like to request
With Next.js 13 a lot changed for the better. However, It looks like the server functions for fetching data don't have access to the request like getServerSideProps did in Next.js 12. It appears they only have access to url params, but not the entire request object which is odd and unfortunate. I think it would be beneficial to at least make it available somehow in the page file of a route in the app directory. Sites and platforms that are domain name driven would need it.
Describe the solution you'd like
The solution would look something like this:
//app/hello/page.js file
export default function Page({params, searchParams, request}) {
//so that request can be passed into any data fetching function and can validated
return <h1>Hello, Next.js!</h1>;
}
Describe alternatives you've considered
Basically, the same thing, just make people parse the url from the request object for the params themselves I guess?
//app/hello/page.js file
export default function Page({request}) {
//so that request can be passed into any data fetching function and can validated
return <h1>Hello, Next.js!</h1>;
}