Advertisement

Next.js Sitemap Generator

Our Next.js Sitemap Generator crawls your deployed application to extract all rendered routes. Use it to verify your dynamic route generation or to create a static sitemap file for SSG builds.

How to Use This Tool

1
1

Enter Next.js URL

Input the homepage URL of your Next.js application URL.
2
2

Analyze Site

Click generate to let our crawler map your Next.js architecture, including posts, pages, and products.
3
3

Review URLs

Check the discovered URLs. We exclude default Next.js system pages and non-indexable routes.
4
4

Choose Output

Select either a standard 'Single Sitemap' or 'Sitemap Index' format.
5
5

Copy or Download

Save the generated XML file directly to your device.
6
6

Recommended Action

Upload the sitemap to your root directory (if allowed by Next.js) and submit it via Google Search Console.

How Next.js Handles Sitemaps

In the Next.js App Router, sitemaps are typically generated dynamically using a `sitemap.ts` file placed at the root of the `app/` directory. This file exports an async function that returns an array of URL objects.

If you are using the older Pages Router or building a completely static export (SSG), you often rely on external packages like `next-sitemap` run as a post-build script.

What BuildSitemap Checks

Because Next.js applications often combine static, server-rendered (SSR), and incremental static regeneration (ISR) routes, bugs in your `sitemap.ts` database queries can lead to missing URLs.

BuildSitemap acts as a black-box tester. We crawl the live production deployment, following your actual React Router `Link` components. This verifies if the URLs your `sitemap.ts` is outputting actually match the links users can access.

URLs We Discover

  • Static App Router pages (/app/page.tsx)
  • Dynamic routes (/app/[slug]/page.tsx)
  • API endpoints (if accidentally linked)
  • ISR generated pages

URLs to Exclude

  • Route Handlers (/api/*) that do not return HTML
  • Protected application states (/dashboard/*)
  • Parameterized search URLs
  • Error boundaries or suspense fallback states

Next.js Sitemap Structure

For large Next.js applications (like a headless ecommerce store or content portal), you must shard your sitemap in Next.js 13+.

Using our Structured Sitemap tool can help you identify exactly how to bucket your dynamic routes (e.g., separating `/blog/[slug]` from `/product/[id]`) so you can implement the `generateSitemaps` function efficiently in your Next.js codebase.

Common Next.js Problems

Returning more than 50,000 URLs from a single `sitemap.ts` file, causing Google to reject the file.

Failing to account for pagination in the database queries powering the dynamic sitemap generation.

Mismatch between the base URL in the sitemap (e.g., HTTP vs HTTPS) and the deployed environment.

How to Use Your Generated Sitemap

While you should ideally code a dynamic `sitemap.ts` for Next.js, our tool is incredibly useful for:

  1. Static Exports: If you are using `output: 'export'`, you can use our tool to generate a static XML file and drop it into your `public/` folder.
  2. Auditing: Compare the output of our external crawl against the output of your `/sitemap.xml` route to find missing database entries or orphaned pages.
Advertisement
Advertisement

Example Next.js Output

import { MetadataRoute } from 'next'
 
export default function sitemap(): MetadataRoute.Sitemap {
  return [
    {
      url: 'https://nextjs.example.com',
      lastModified: new Date(),
    },
    {
      url: 'https://nextjs.example.com/blog/app-router',
      lastModified: new Date(),
    },
  ]
}

Best Practice Checklist

Frequently Asked Questions

How do I create a sitemap in Next.js App Router?

Create a `sitemap.ts` or `sitemap.js` file in the root of your `app/` directory and export a function that returns your URLs.

What if I have more than 50,000 URLs?

In Next.js 13.3+, you can export a `generateSitemaps` function from your `sitemap.ts` file to split your sitemap into multiple files.

Can I use BuildSitemap for a static Next.js site?

Yes. If you build your site statically, you can crawl it with BuildSitemap, download the XML, and place it in your `public/` directory.

Does Next.js cache the sitemap?

Yes, by default Next.js caches the output of `sitemap.ts`. If your data updates frequently, you may need to configure route segment config options like `export const revalidate = 0;` to ensure freshness.

How do I add dynamic routes to my Next.js sitemap?

Inside your `sitemap.ts` function, you will typically fetch data from your CMS or database, map over those items, and return an array of URL objects formatted for your dynamic routes.

Is next-sitemap still necessary for App Router?

No, the App Router's native `sitemap.ts` API replaces the need for third-party packages like `next-sitemap` in most modern Next.js applications.

Related Tools

Advertisement
Advertisement