英文:
What does _app.js and _document.js file do? What's "_" (Underscore) for in next.js?
问题
以下是翻译的内容:
当我使用npx create-next-app
创建一个Next.js应用程序时,会有两个以下划线开头的JS文件,分别命名为app和document,这是用来做什么的?
这两个文件的结构如下:
▼ 页面
_app.js
_document.js
英文:
When I created a next.js app using npx create-next-app
there is 2 js files named app and document leading with an Underscore what is that for?
The files are like this:
▼ pages
_app.js
_document.js
答案1
得分: 2
这是一种约定。 _
表示文件是部分的,不应该暴露给用户作为页面。
以下是来自Next.js的一位贡献者的引用。
实际上,我们使用下划线(_)前缀表示“私有”(内部的,但实际上并不是机密的)页面,这基于通常使用下划线来表示这种约定。来源
英文:
It is a matter of convention. _
indicates that the file is partial and not supposed to be exposed as a page to the user.
Here is a quote from one of the contributors of Next.js.
> We actually use the underscore (_) prefix for 'private' (internal, but not actually secret) pages, based on common convention of underscores often being used to denote that.
答案2
得分: 0
通过使用下划线前缀命名这些文件,Next.js 表示它们是特殊文件,不应该由用户直接访问。相反,它们应该被用作模板或样板代码,可以根据您的应用程序的特定需求进行修改。
英文:
By naming these files with an underscore prefix, Next.js indicates that they are special files that should not be directly accessed by the user. Instead, they are meant to be used as templates or boilerplate codes that can be modified to fit the specific needs of your application.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论