Replacing App.getInitialProps and the general lack of context in app router
Unanswered
New Guinea Freshwater Crocodile posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
New Guinea Freshwater CrocodileOP
I'm looking at migrating a project using the pages router, it's using
It seems with layouts and the new app router there's no longer any context at all, and no way to streamline global props in a single place. I've seen some ideas of using a React context for this and even mentions of state libraries, but that seems incredibly backwards since these are things that are not related to React at all and is just simple HTTP-stuff. We also used simple properties on the page functions like
This is completely missing from all migration guides, they only cover very simple things like the html wrapping the page and localised page functionality.
App.getInitialProps = async (context: AppContext) => {...
to setup a lot of props for pages (based on the incoming request) and we also use the context
prop in different pages to read headers etc. We need to be able to parse the HTTP request, not just the Next search and router params.It seems with layouts and the new app router there's no longer any context at all, and no way to streamline global props in a single place. I've seen some ideas of using a React context for this and even mentions of state libraries, but that seems incredibly backwards since these are things that are not related to React at all and is just simple HTTP-stuff. We also used simple properties on the page functions like
Page.authenticationNeeded
which we read in the _app
file, but since this is now just a children prop we lose basic JS functionality here too.This is completely missing from all migration guides, they only cover very simple things like the html wrapping the page and localised page functionality.
3 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Thai Ridgeback
Hi @New Guinea Freshwater Crocodile , did you find out what the right way to do this was? I'm having the same problem
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
New Guinea Freshwater CrocodileOP
@Thai Ridgeback Unfortunately not, migrating to the app router is pretty much impossible for us due to how limited it is and the arbitrary design choices Vercel has made. https://github.com/vercel/next.js/issues/43704 is my favorite issue so far, no fix in sight
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Thai Ridgeback
oh god I was trying to find how to do this ðŸ˜