DocsDeveloper

Sitemap and Robots

Overview

In Next.js, the sitemap.ts and robots.ts files serve crucial roles in enhancing the discoverability and search engine optimization (SEO) of web applications. The sitemap.ts file enables developers to generate and maintain a structured sitemap, providing search engines with clear navigation paths to all accessible pages within the application. This facilitates efficient indexing by search engine crawlers, leading to improved visibility and ranking in search engine results. On the other hand, the robots.ts file allows developers to define directives for search engine bots, regulating which pages should be crawled and indexed. By strategically configuring the robots.ts file, developers can prevent search engines from indexing sensitive or irrelevant content, ensuring better control over the visibility and accessibility of their web application. Incorporating these files into a Next.js project is paramount for maximizing online presence, user engagement, and overall success in the digital landscape.

Simply run the command, and these essential SEO files will be automatically generated for you. All that's left for you to do is navigate to the newly created sitemap.ts file and replace the example text with your site URLs. Take control of your website's SEO strategy effortlessly, saving time and ensuring your site is properly indexed by search engines

Easy CLI Install

jrui create sitemap robots

Component Files

app > sitemap.ts

import { MetadataRoute } from "next";

export default function sitemap(): MetadataRoute.Sitemap {
  return [
    {
      url: "https://your-domain-name.whatever/",
    },
    {
      url: "https://your-domain-name.whatever/docs",
    },
    {
      url: "https://your-domain-name.whatever/docs/pick-a-template",
    },
  ];
}

app > robots.ts

import { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
  return {
    rules: {
      userAgent: "*",
      allow: "/",
    },
    sitemap: "https://your-domain-name.whatever/sitemap.xml",
  };
}