Home > Mobile >  Is there a index.html template page in NextJS?
Is there a index.html template page in NextJS?

Time:12-24

I started using NextJS today, porting a ReactJS website to it. It seems to be a great framework, but I am missing one thing.

In pure ReactJS (no NextJS framework) there is a public/index.html page which serves as a template where all ReactJS components are mounted. In certain situations, when I need to add a certain script in all my pages, I just edit public/index.html and add the script to its <head></head> section.

A good example is my FontAwesome kit, which I add to all my ReactJS pages by inserting

<script src="https://kit.fontawesome.com/9999999999.js" crossorigin="anonymous"></script>

to <head></head> section of public/index.html.

I searched the basic structure of a NextJS project and found no equivalent file.

How can I do the same using NextJS?

CodePudding user response:

We have _document.tsx file (generate one under pages folder if you do not have it yet). You can see its content on each page.

https://nextjs.org/docs/advanced-features/custom-document

Between Head tags you can use NextJs Script component to run your scripts

https://nextjs.org/docs/api-reference/next/script

CodePudding user response:

In the index.tsx or index.js file, you will find you are able to use <Head></Head> which serves the same purpose.

  • Related