author avatar

adithya.hebbar

Wed Oct 23 2024

Here is how to generate robots.txt in Next.Js - App Router. Add a robots.js or robots.ts file in your app directory


import type { MetadataRoute } from 'next'
 
export default function robots(): MetadataRoute.Robots {
  return {
    rules: {
      userAgent: '*',
      allow: '/',
      disallow: '/private/',
    },
  }
}


This will add or generate a robots.txt file that matches the Robots Exclusion Standard in the root of app directory to tell search engine crawlers which URLs they can access on your site.

#js #nextjs #seo