Why does Next.js prefix the app.js with an underscore?

Viewed 4411

When I create a Next.js project with the npx create-next-app command than there is an _app.js file under the pages folder. In which case do I need to prefix a file with an underscore in a Next.js project?

2 Answers

Next.js uses the App component to initialize pages.

To override the default App, create the file ./pages/_app.js


A custom Document is commonly used to augment your application's <html> and <body> tags.

To override the default Document, create the file ./pages/_document.js

You're only gonna need that prefix in the default nextjs pages like _app.js, the _document.js, etc. you can look it up in the Next.js Docs, I think the prefix is used to avoid routes like "/app" or "/document", and let them free in case you need use them for your project.

Related