Skip to content

ctx.req is undefined in Document #18235

Answered by jamesmosier
bluelovers asked this question in Help
Discussion options

You must be logged in to vote

Hi @bluelovers. _document.js is not the recommended place for code like this. Document is not meant to hold application logic like this. There are also some other caveats](https://nextjs.org/docs/advanced-features/custom-document#caveats) too.

Code like what you have above should be put in _app.js. That will achieve what you are looking for and will run on every page.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@eschaefer
Comment options

Answer selected by jamesmosier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #18235 on October 26, 2020 01:01.