Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? In the Next tutorial it says to change the index.js but what is rendered for me is _app.js.

like image 258
Henrique Ramos Avatar asked Nov 21 '25 00:11

Henrique Ramos


1 Answers

_app.js will contain your whole app, meaning this will be rendered in any page of the project. 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. More reading here.

index.js will only be rendered if you access / path of your website. 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. More reading here .

like image 174
Mentlegen Avatar answered Nov 22 '25 13:11

Mentlegen