Canonical URLs in Vue · Nuxt SEO

-
-
-
-

[1.4K](https://github.com/harlan-zw/nuxt-seo)

[Nuxt SEO on GitHub](https://github.com/harlan-zw/nuxt-seo)

Learn SEO

Master search optimization

Nuxt

 Vue

-
-
-
-
-
-
-

-
-
-
-
-
-
-

-
-
-

-
-
-
-
-
-
-
-
-
-
-

-
-
-

-
-
-
-
-
-
-
-
-

1.
2.
3.
4.
5.

# Canonical URLs in Vue

Canonical URLs tell search engines which version of a page to index when duplicate content exists. Here's how to set them up in Vue.

[![Harlan Wilton](https://avatars.githubusercontent.com/u/5326365?v=4)Harlan Wilton](https://x.com/harlan-zw)10 mins read Published Nov 3, 2024 Updated Jan 29, 2026

What you'll learn

- Vue Router doesn't set canonicals automatically; use `@unhead/vue` to add them per route
- Canonical tags are hints, not directives. Google may choose a different canonical
- Always use absolute URLs ([https://mysite.com/page](https://mysite.com/page), not /page)
- Self-referencing canonicals are recommended even for unique pages

In Vue applications, canonical URLs require manual setup using `@unhead/vue` and Vue Router. Unlike Nuxt, which handles canonicals automatically through site config, Vue developers must explicitly set the `rel="canonical"` link tag for every route. [67.6% of websites have duplicate content issues](https://www.womenintechseo.com/knowledge/dealing-with-duplicate-content-canonicalization-in-detail/) due to poor canonicalization.

Use canonicals for URLs with query parameters (filters, sorting), same content on multiple paths, paginated sequences, and cross-domain syndication. For choosing between canonicals and redirects, see

. For redirecting users, use

 instead. For blocking pages from search, use

 with noindex.

## [Quick Setup](#quick-setup)

Add canonical URLs to your Vue pages using Unhead composables:

Basic Usage

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'

useHead({
  link: [
    {
      rel: 'canonical',
      href: 'https://mysite.com/products/phone'
    }
  ]
})
</script>
```

With Query Params

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'

const sort = 'price'

// Keep sort parameter in canonical
useHead({
  link: [
    {
      rel: 'canonical',
      href: \`https://mysite.com/products?sort=${sort}\`
    }
  ]
})
</script>
```

Cross Domain

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'

useHead({
  link: [
    {
      rel: 'canonical',
      href: 'https://otherdomain.com/original-article'
    }
  ]
})
</script>
```

For Vue applications, you'll need to [install Unhead manually](https://unhead.unjs.io/guide/getting-started/installation).

## [Understanding Canonical URLs](#understanding-canonical-urls)

A canonical URL is implemented as a link tag in your page's head:

```
<link rel="canonical" href="https://mysite.com/page">
```

### [Canonical Tags Are Hints, Not Directives](#canonical-tags-are-hints-not-directives)

Google treats canonicals as [strong signals, not mandatory rules](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls). Google's Joachim Kupke: "It's a hint that we honor strongly. We'll take your preference into account, in conjunction with other signals, when calculating the most relevant page to display in search results."

Google may choose a different canonical than you specify when:

- Content differs significantly between URLs
- Multiple conflicting canonical declarations exist
- Google believes a different page is more authoritative

[Google uses the canonical page](https://developers.google.com/search/docs/crawling-indexing/canonicalization) as the main source to evaluate content and quality. Non-canonical URLs may still be crawled but usually won't appear in search results.

### [Self-Referencing Canonicals](#self-referencing-canonicals)

[Self-referencing canonicals are recommended](https://searchengineland.com/canonicalization-seo-448161) even for unique pages. They establish a clear preferred URL and prevent search engines from guessing when tracking parameters or alternate URL formats appear.

Google's John Mueller: "I recommend using a self-referential canonical because it makes it clear to us which page you want to have indexed, or what the URL should be when it is indexed."

### [Important Notes](#important-notes)

- Must use absolute URLs ([Google documentation](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls))
- Only one canonical per page (multiple declarations cause Google to ignore all hints)
- Must be server-side rendered (crawlers don't run JavaScript)
- Include canonical pages in, exclude non-canonical pages
- Don't combine canonical with noindex. sends conflicting signals

Google may ignore your canonical if the target page's content differs significantly from the source. Canonicals should point to pages with substantially similar content. not a different page or your homepage.

## [Common Patterns](#common-patterns)

### [Filter and Sort Parameters](#filter-and-sort-parameters)

pages/products/[category].vue

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const { sort } = route.query
const category = route.params.category

useHead({
  link: [{
    rel: 'canonical',
    // Only include sort in canonical, remove filter and pagination
    href: sort
      ? \`https://mysite.com/products/${category}?sort=${sort}\`
      : \`https://mysite.com/products/${category}\`
  }]
})
</script>
```

### [Pagination](#pagination)

Paginated pages need self-referencing canonicals. [Don't point them all to page 1](https://developers.google.com/search/docs/specialty/ecommerce/pagination-and-incremental-page-loading), because each page in the sequence has unique content and should be indexed separately. See the

 for implementation details.

### [Mobile/Desktop Versions](#mobiledesktop-versions)

If you have separate mobile URLs (m.domain.com), [keep the desktop URL as canonical](https://www.lumar.io/office-hours/separate-mobile/) even with mobile-first indexing. Google uses canonicals to understand which pages belong together, then internally selects the mobile version for indexing.

pages/products/[id].vue

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const id = route.params.id

useHead({
  link: [{
    rel: 'canonical',
    // Mobile site (m.mysite.com) points to desktop
    href: \`https://mysite.com/products/${id}\`
  }]
})
</script>
```

[Don't switch canonicals from desktop to mobile URLs](https://www.seroundtable.com/google-m-dot-urls-the-canonical-37809.html). Google advises against this. Use responsive design with a single URL instead.

### [Cross-Domain Syndication](#cross-domain-syndication)

[Google no longer recommends cross-domain canonicals](https://searchengineland.com/google-no-longer-recommends-canonical-tags-for-syndicated-content-406491) for syndicated content. Instead, syndication partners should use noindex meta robots to block indexing.

pages/article/[slug].vue

```
<script setup lang="ts">
import { useSeoMeta } from '@unhead/vue'

// If syndicating TO other sites, have them use noindex
useSeoMeta({
  robots: 'noindex, follow'
})
</script>
```

pages/original-article.vue

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'

// If this IS the original, use self-referencing canonical
useHead({
  link: [{
    rel: 'canonical',
    href: 'https://mysite.com/articles/original-slug'
  }]
})
</script>
```

Exception: News publishers syndicating to Google News should still use cross-domain canonicals per [Google's news publisher guidance](https://developers.google.com/search/blog/2009/12/handling-legitimate-cross-domain).

## [Testing](#testing)

### [Verifying Canonicals](#verifying-canonicals)

Use [Google Search Console's URL Inspection tool](https://support.google.com/webmasters/answer/9012289) to compare your declared canonical with Google's selected canonical. For a full detection workflow, see

.
### [Important Checks](#important-checks)

- Validate absolute URL format
- Check for canonical chains (A → B → C)
- Verify SSR implementation (view page source, not inspected HTML)
- Test with and without parameters
- Don't combine canonical with noindex

## [Handling Edge Cases](#handling-edge-cases)

### [Multiple Language Versions](#multiple-language-versions)

For multilingual sites, combine canonicals with hreflang:

```
<script setup lang="ts">
import { useHead } from '@unhead/vue'

useHead({
  link: [
    {
      rel: 'canonical',
      href: 'https://mysite.com/en/page'
    },
    {
      rel: 'alternate',
      hreflang: 'fr',
      href: 'https://mysite.com/fr/page'
    }
  ]
})
</script>
```

### [Protocol/WWW Variations](#protocolwww-variations)

Handle through

 rather than canonicals:

Express

Vite

H3

```
import express from 'express'

const app = express()

app.use((req, res, next) => {
  const host = req.get('host')
  if (!host.startsWith('www.')) {
    return res.redirect(301, \`https://www.${host}${req.path}\`)
  }
  next()
})
```

```
// server.js for Vite SSR
import express from 'express'

const app = express()

app.use((req, res, next) => {
  const host = req.get('host')
  if (!host.startsWith('www.')) {
    return res.redirect(301, \`https://www.${host}${req.path}\`)
  }
  next()
})
```

```
import { defineEventHandler, getRequestHost, sendRedirect } from 'h3'

export default defineEventHandler((event) => {
  const host = getRequestHost(event)
  if (!host.startsWith('www.')) {
    return sendRedirect(event, \`https://www.${host}${event.path}\`, 301)
  }
})
```

### [Dynamic Canonicals](#dynamic-canonicals)

For dynamic routes, ensure canonical URLs are consistent:

composables/useCanonical.ts

```
export function getCanonical(path: string) {
  const siteUrl = import.meta.env.VITE_SITE_URL
  return {
    link: [{
      rel: 'canonical',
      href: \`${siteUrl}${path}\`
    }]
  }
}
```

## [Using Nuxt?](#using-nuxt)

If you're using Nuxt, check out

 which handles much of this automatically.

---

On this page

- [Quick Setup](#quick-setup)
- [Understanding Canonical URLs](#understanding-canonical-urls)
- [Common Patterns](#common-patterns)
- [Testing](#testing)
- [Handling Edge Cases](#handling-edge-cases)
- [Using Nuxt?](#using-nuxt)

[GitHub](https://github.com/harlan-zw/nuxt-seo) [ Discord](https://discord.com/invite/275MBUBvgP)

###

-
-

Modules

-
-
-
-
-
-
-
-
-

###

-
-
-

###

Nuxt

-
-
-
-
-

Vue

-
-
-
-
-
-
-
-

###

-
-
-
-
-
-
-
-
-
-

Copyright © 2023-2026 Harlan Wilton - [MIT License](https://github.com/harlan-zw/nuxt-seo/blob/main/license) · [mdream](https://mdream.dev)