Robots
Guides

Config using Nuxt Config

Learn how to configure the module programmatically using nuxt.config.

If you need programmatic control, you can configure the module using nuxt.config.

Simple Configuration

The simplest configuration is to provide an array of paths to disallow for the * user-agent. If needed you can provide allow pat You can simply add the path or path pattern to hs as well.

  • disallow - An array of paths to disallow for the * user-agent.
  • allow - An array of paths to allow for the * user-agent.
nuxt.config.ts
export default defineNuxtConfig({
  robots: {
    // provide simple disallow rules for all robots `user-agent: *`
    disallow: ['/secret', '/admin'],
    allow: '/admin/login'
  }
})

This will generate the following output:

User-agent: *
Disallow: /secret
Disallow: /admin
Allow: /admin/login

Group Configuration

When targeting specific robots, you can use the groups option to provide granular control.

  • groups - A stack of objects to provide granular control (see below).
nuxt.config.ts
export default defineNuxtConfig({
  // add more granular rules
  groups: [
    // block specific robots from specific pages
    {
      userAgents: ['AdsBot-Google-Mobile', 'AdsBot-Google-Mobile-Apps'],
      disallow: ['/admin'],
      allow: ['/admin/login'],
      comments: 'Allow Google AdsBot to index the login page but no-admin pages'
    },
  ]
})

This will generate the following output:

# Allow Google AdsBot to index the login page but no-admin pages
User-agent: AdsBot-Google-Mobile
User-agent: AdsBot-Google-Mobile-Apps
Disallow: /admin
Allow: /admin/login