Next.js: Is it possible to have multiple custom documents?

Created on 22 Aug 2017  路  5Comments  路  Source: vercel/next.js

The docs say you can define a custom document at pages/_document.js.

But is there any way to make two pages that use different custom documents?

Most helpful comment

You need to have a single pages/_document.js and you can then check the URL before rendering to change the HTML you're going to render.

All 5 comments

You need to have a single pages/_document.js and you can then check the URL before rendering to change the HTML you're going to render.

That makes of a lot more sense than what I was imagining

@sergiodxa this sounds like an excellent approach!

Can you give a simple example of this?

I can get _document.js to identify URL (query, pathname) on first load, but struggling with _document.js identify when the Routes are changed.

Thanks!

_document.js is only rendered once on the server, all navigation using is client side.

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings