simple-robots
Go to documentationSimply manage the robots crawling your Nuxt app.
nuxt-simple-robots
Simply manage the robots crawling your Nuxt 3 app.
Status: Stable Please report any issues 🐛 Made possible by my Sponsor Program 💖 Follow me @harlan_zw 🐦 • Join Discord for help |
ℹ️ Looking for a complete SEO solution? Check out Nuxt SEO Kit.
Features
- 🤖 Creates best practice robot data
- 🗿 Adds
X-Robots-Tag
header, robot meta tag and robots.txt - 🔄 Configure using route rules
- 🔒 Disables non-production environments from being crawled automatically
- Best practice default config
Install
npm install --save-dev nuxt-simple-robots# Using yarnyarn add --dev nuxt-simple-robots
Setup
nuxt.config.ts
export default defineNuxtConfig({ modules: [ 'nuxt-simple-robots', ],})
Configure route indexing
Using route rules, you can configure how your routes are indexed by search engines.
export default defineNuxtConfig({ routeRules: { // use the `index` shortcut for simple rules '/secret/**': { index: false }, // add exceptions for individual routes '/secret/visible': { index: true }, // use the `robots` rule if you need finer control '/custom-robots': { robots: 'index, follow' }, }})
Injecting Meta Tags (optional)
By default, only the robots.txt and HTTP headers will be used to control indexing. If you want to add a meta tag to your page as well, you can use the composable or the component provided.
This shouldn't be necessary, but it's useful if you want to be extra sure that your page is not indexed and can make debugging easier.
Within your app.vue or a layout:
<script lang="ts" setup>// Use Composition APIdefineRobotMeta()</script><template> <div> <!-- OR Component API --> <RobotMeta /> </div></template>
Module Config
indexable
- Type:
boolean
- Default:
process.env.NUXT_INDEXABLE || nuxt.options.runtimeConfig.indexable || process.env.NODE_ENV === 'production'
Whether the site is indexable by search engines.
disallow
- Type:
string[]
- Default:
[]
- Required:
false
Disallow paths from being crawled.
sitemap
- Type:
string | string[] | false
- Default:
false
The sitemap URL(s) for the site. If you have multiple sitemaps, you can provide an array of URLs.
You must either define the runtime config siteUrl
or provide the sitemap as absolute URLs.
// option 1. provide runtime config for site urlexport default defineNuxtConfig({ runtimeConfig: { siteUrl: process.env.NUXT_PUBLIC_SITE_URL || 'https://example.com', }, robots: { sitemap: '/sitemap.xml', },})
// option 2. provide absolute URLsexport default defineNuxtConfig({ robots: { sitemap: [ 'https://example.com/sitemap.xml', ], },})
robotsEnabledValue
- Type:
string
- Default:
'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1'
- Required:
false
The value to use when the site is indexable.
robotsDisabledValue
- Type:
string
- Default:
'noindex, nofollow'
- Required:
false
The value to use when the site is not indexable.
Sponsors
License
MIT License © 2022-PRESENT Harlan Wilton