How to add a sitemap to a NextJS website

Oscar de la Hera Gomez
A flower that represents NextJS with the text "Sitemap" beneath it.

A tutorial for creating static or dynamic sitemaps in a NextJS project.

The following post explains how to generate a sitemap using the NextJS app router.

If you are not familiar with the NextJS app router, consult the link below.

The tutorial follows the principles laid out in the official NextJS documentation linked below.

In a file called sitemap.ts at the root of the app folder, do one of the following:

A/ Static Sitemap

A screenshot of the NextJS website showing the documentation for creating a static sitemap.

Add your URLs in a similar way to that described in the documentation.

B/ Dynamic Sitemap

A screenshot of the dynamic sitemap that we created for the student archive.

To make a sitemap dynamic, you must export an asynchronous function that returns a promise.

async function Sitemap(): Promise<MetadataRoute.Sitemap>

Then within the function make the neccesary API calls and return an array similar to that illustrated in the documentation.

Looking to learn more about NextJS, ReactJS or web development?

Search our blog to find educational content on NextJS, ReactJS and web development.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details