Sitemap for NextJS Application


There is a really handy npm package to create sitemaps for your NextJS application, next-sitemap can be used for both main pages and also dynamically created pages. Be able to use this:

First, install the package:

npm i next-sitemap

Add postbuild script to package.json:

"postbuild": "next-sitemap"

Create a file for the configurations in the root folder named next-sitemap.config.js

module.exports = {
    siteUrl: process.env.NEXT_PUBLIC_BASE_URL,
    generateRobotsTxt: true,
    exclude: ["/api/**"],
    robotsTxtOptions: {
        additionalSitemaps: [

Now, when you navigate the you will get all the dynamically created sitemap URLs.