Nuxt SEO: meta tags, canonical URLs and the sitemap
Nuxt SEO in code: titles with useSeoMeta, one canonical per page, a sitemap with real dates, and what changes when you build the site as static files.
Nuxt SEO is mostly four things: a title and description on every page with useSeoMeta, one canonical URL per page, a sitemap that reports real dates, and knowing which pages your build renders ahead of time. Nuxt renders pages on the server by default, so the tags you write are in the HTML Google reads. What it leaves to you is the canonical, the sitemap and the dates in it.
Below is the code for each step, a checklist to run before a launch, and what to do after it. The examples follow the Nuxt 4 docs, linked at the end.
TL;DR:
- Leave server rendering on. It is the default, and it is what puts your content in the HTML.
- Set each page's title and description with
useSeoMeta, and add a title template once inapp.vue. - Core Nuxt prints no canonical tag. Add one in
app.vue, built from a site URL you configure. - Add
@nuxtjs/sitemap, setsite.url, and givelastmodthe date the content changed. - On a static build, only pages the crawler can reach through a link get an HTML file.
What does Nuxt already do for SEO?
It sends finished HTML. The docs say "By default, Nuxt uses universal rendering to provide better user experience, performance and to optimize search engine indexing", and explain why that helps: "as the content is already present in the HTML document, crawlers can index it without overhead."
The setting that undoes this is ssr: false. The same page is plain about the cost of rendering only in the browser: "Your content will take more time to show and update in search results pages with pure client-side rendering." It recommends that mode for apps "that don't need indexing", such as a dashboard behind a login.
You can mix the two per route, which is the usual shape for a site with a marketing side and an app side:
// nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/': { prerender: true },
'/blog/**': { prerender: true },
'/admin/**': { ssr: false },
},
})
Nuxt adds two tags by default, charset and viewport. Everything else in the <head> is yours to write.
How do you set meta tags in Nuxt?
Call useSeoMeta in the page. The docs describe it as a way to "define your site's SEO meta tags as an object with full type safety", which "helps you avoid typos and common mistakes, such as using name instead of property." That second part matters for Open Graph tags, where the wrong attribute fails without any error.
<!-- app/pages/pricing.vue -->
<script setup lang="ts">
useSeoMeta({
title: 'Pricing',
description: 'Three plans. Every feature in each one.',
ogTitle: 'Pricing',
ogDescription: 'Three plans. Every feature in each one.',
})
</script>
Then set the parts that never change once, in app.vue. A title template adds the site name to every page's title:
<!-- app/app.vue -->
<script setup lang="ts">
useHead({
htmlAttrs: { lang: 'en' },
titleTemplate: (title) => (title ? `${title} - Example` : 'Example'),
})
</script>
The docs note that a template written as a function "cannot be set in your nuxt.config", which is why it lives in app.vue. A string form, '%s - Example', works in either place.
For a page built from data, pass the fields in as getters so the tags follow the data:
<!-- app/pages/blog/[slug].vue -->
<script setup lang="ts">
const route = useRoute()
const { data: post } = await useFetch(`/api/posts/${route.params.slug}`)
useSeoMeta({
title: () => post.value?.title,
description: () => post.value?.description,
})
</script>
Because the page awaits its data on the server, the title is in the HTML response. A title set only after a fetch in the browser is the thing to avoid.
How do you add a canonical URL in Nuxt?
Add a link tag with useHead in app.vue, built from the current path and a site URL you set in config. Core Nuxt does not print a canonical for you.
// nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
public: {
siteUrl: 'https://example.com', // NUXT_PUBLIC_SITE_URL overrides it
},
},
})
<!-- app/app.vue -->
<script setup lang="ts">
const route = useRoute()
const { siteUrl } = useRuntimeConfig().public
useHead({
link: [
{ rel: 'canonical', href: () => siteUrl + route.path },
],
})
</script>
route.path leaves the query string out, so /pricing?ref=newsletter and /pricing name the same canonical.
Build it from config, not from the request. Nuxt has a useRequestURL helper, and it is tempting to read the host from it. The docs warn that on routes served through the cache, request headers are dropped, "meaning useRequestURL will return localhost for the host". A canonical pointing at localhost is worse than none.
If you would rather not write this yourself, the Nuxt SEO Utils module lists "Automatically generate canonical URLs for all pages" among its defaults.
Trailing slashes need one decision. Request a page with and without the slash on your host and see what comes back. If both answer 200, the canonical above is what tells Google which one counts, so make your internal links use the same form.
How do you add a sitemap in Nuxt?
Use the @nuxtjs/sitemap module. Nuxt has no sitemap of its own.
npx nuxt module add @nuxtjs/sitemap
Then tell it your address. Its docs say "At a minimum the module requires a Site URL to be set", and what happens otherwise: "Without a Site URL, your sitemap will use localhost in production."
// nuxt.config.ts
export default defineNuxtConfig({
site: {
url: 'https://example.com',
},
})
The sitemap is served at /sitemap.xml and lists the pages the module finds in your app. Routes that come from a database or a CMS are not files it can see, so you hand those over from a server endpoint:
// server/api/__sitemap__/urls.ts
import { defineSitemapEventHandler } from '#sitemap/server'
export default defineSitemapEventHandler(async () => {
const posts = await getPublishedPosts() // your own query
return posts.map((post) => ({
loc: `/blog/${post.slug}`,
lastmod: post.contentChangedAt,
}))
})
For robots.txt there is a sister module, added with npx nuxt module add robots.
Try it
Point an SEO agent at your own site, not just an essay about one.
QueryScope holds the plan for your site, reads your real Search Console, and hands the coding agent you already have one change at a time to rank for the searches you decided to win. From $49/month, everything included.
Why does lastmod need real dates?
Because Google only trusts the field while it is true. Its docs say it uses lastmod "if it's consistently and verifiably" accurate, and that the value "should reflect the date and time of the last significant update to the page".
The easy mistake is a default. The module lets you set one date for every entry, and its own example of that is lastmod: new Date().toISOString(), shown under a note that this "is not recommended". With that in place every URL claims to have changed at the last build.
Give each page its own date instead. In the endpoint above, that is the day the post's text changed, not the day a row was last saved. With Nuxt Content, the module reads a sitemap key from the frontmatter, once the collection's schema includes its defineSitemapSchema():
---
title: Pricing changes in November
sitemap:
lastmod: 2026-11-17
---
How Google uses lastmod goes through what counts as a change.
What changes when you build a static site?
nuxt generate writes every page as an HTML file, and it finds pages by following links. The docs describe the crawler's last step as "Repeat steps 1-3 for each anchor tag found until there are no more anchor tags to crawl." A page nothing links to is never found, so it gets no file.
List those pages yourself:
// nuxt.config.ts
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/sitemap.xml', '/robots.txt', '/landing/black-friday'],
},
},
})
Two more things from the docs are worth knowing before you pick this mode. You cannot mix modes per route: "Hybrid Rendering is not available when using nuxt generate." And the not-found page starts empty: "By default 404.html is an empty shell", so your error page only appears once the JavaScript has loaded. The rendering docs show how to prerender it.
A Nuxt SEO checklist before launch
Run this against a production build, not the dev server.
- Server rendering is on for every page you want in search. Search the config for
ssr: false. - Every page sets its own title and description. View the page source, not the browser tab.
- Every page prints one canonical, on the production domain, with no query string and no
localhost. site.urlis set, and/sitemap.xmllists production URLs.lastmodvalues are content dates. No two unrelated pages share today's.- On a static build, every page has a file. Compare the output folder with your sitemap.
- No
noindexleft over from staging. - One URL per page: one slash form in links, the canonical and the sitemap.
What do you change next, and how do you know it worked?
Setup gets a page into Google. It does not tell you which page to work on, and that is the question a client asks a month after launch. The answer is in Search Console: which searches the site already shows for, where it sits on each, and which pages Google has not indexed.
A Nuxt site with its pages in the repo suits this, because every change is a commit with a date. If you build Nuxt sites for clients, SEO for web agencies that build client sites in code shows how QueryScope handles it: a plan per client site, one change at a time from your coding agent, and a dated record of every change. The same guide exists for Astro and for Next.js.
Sources
- Nuxt docs, SEO and Meta (
useHead,useSeoMetaand its type safety; the defaultcharsetandviewporttags;titleTemplateas a string or a function; getters for reactive values). - Nuxt docs, Rendering modes (universal rendering by default; the cost of client-side rendering for indexing;
ssr: false;routeRules; no hybrid rendering withnuxt generate; the empty404.html). - Nuxt docs, Prerendering (
nuxt generate; how the crawler follows anchor tags;nitro.prerender.routesandcrawlLinks). - Nuxt docs, useRequestURL (returns
localhostas the host on cached responses). - Nuxt docs, Runtime config (
runtimeConfig.publicand itsNUXT_PUBLIC_environment variables). - Nuxt SEO docs, Sitemap: installation (
npx nuxt module add @nuxtjs/sitemap; the Site URL requirement;/sitemap.xml), dynamic URLs (defineSitemapEventHandler; thelocandlastmodfields), lastmod, priority and changefreq (thedefaultsoption) and Nuxt Content (thesitemapfrontmatter key). - Nuxt SEO docs, Robots: installation and SEO Utils (canonical URLs generated for all pages).
- Google Search Central, Build and submit a sitemap (
lastmodused when consistently and verifiably accurate; what counts as a significant update).
Try it
Put an SEO agent in your editor.
Ask your coding agent what to work on. QueryScope reads your real Search Console, holds the searches you decided to win, and hands back one move at a time with the proof it worked. From $49/month, everything included. 1, 3 or 10 sites.