Generate the sitemap.xml file for a Next.js app

Just copy and paste a file that will generate the sitemap.xml for the site, including all routes and their last modified dates.

Requirements

Before using the file, make sure your project meets the following requirements:

  • Next.js 13.3.0 or higher
  • Next.js App Router

Usage

Add the file to your project

Copy the sitemap.ts or sitemap.js file to your project's app folder.

Edit the baseUrl variable

Update the baseUrl variable in the sitemap.ts or sitemap.js file with your site's base URL.

const baseUrl: string = "https://novajs.dev";