简体   繁体   English

NextJs 中的 index.js 和 _app.js 有什么区别?

[英]Whats is the difference between index.js and _app.js in NextJs?

Could someone explain to me what is the difference between index.js file and _app.js?有人可以向我解释 index.js 文件和 _app.js 有什么区别吗? In the Next tutorial it says to change the index.js but what is rendered for me is _app.js.在下一个教程中,它说要更改 index.js,但为我呈现的是 _app.js。

_app.js will contain your whole app, meaning this will be rendered in any page of the project. _app.js将包含您的整个应用程序,这意味着它将在项目的任何页面中呈现。 Eg.例如。 if you add a <div>hello world</div> in this file, you will see the Hello World on each and every page of your website.如果您在此文件中添加<div>hello world</div> ,您将在网站的每个页面上看到 Hello World。 More reading here .更多阅读在这里

index.js will only be rendered if you access / path of your website. index.js只有在您访问网站的/路径时才会呈现。 You will use index files whenever you create a new page, for example you want an about page, you will have an about folder containing an index.js , all of this contained in the pages folder.每当您创建一个新页面时,您都将使用索引文件,例如您想要一个 about 页面,您将拥有一个包含index.js的 about 文件夹,所有这些都包含在pages文件夹中。 More reading here .更多阅读在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM