Next.js Discord

Discord Forum

Replacing App.getInitialProps and the general lack of context in app router

Unanswered
New Guinea Freshwater Crocodile posted this in #help-forum
Open in Discord
Avatar
New Guinea Freshwater CrocodileOP
I'm looking at migrating a project using the pages router, it's using 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.

0 Replies