# Next.js canonical tags

> Set canonical URLs in Next.js App Router metadata, handle dynamic routes and locales, and verify the canonical Google receives.

Canonical: https://scaplet.com/seo/nextjs/canonical-tags

Guide Next.js · Canonical URLs

Set canonical URLs in Next.js App Router metadata, handle dynamic routes and locales, and verify the canonical Google receives.

3 min

read

6

sources

Oct 24, 2026

updated

Scaplet Editorial Team

author

In one line

In the Next.js App Router, set canonical URLs with `metadata.alternates.canonical`. Define `metadataBase` in the root layout so relative URL values resolve to the production host, then provide a page-specific canonical for dynamic routes. Inspect the deployed HTML for one absolute canonical that matches redirects, internal links, and sitemap URLs. Google treats canonicals as signals and can choose another URL.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fcanonical-tags%20(%22Next.js%20canonical%20tags%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fcanonical-tags%20(%22Next.js%20canonical%20tags%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fcanonical-tags%20(%22Next.js%20canonical%20tags%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fcanonical-tags%20(%22Next.js%20canonical%20tags%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 3 parts, 3 minutes.

1. [Set a canonical base in the root layout 01](#set-a-canonical-base-in-the-root-layout)
2. [Generate canonical URLs for dynamic routes 02](#generate-canonical-urls-for-dynamic-routes)
3. [Keep related signals aligned 03](#keep-related-signals-aligned)

_01_Checklist

## Set a canonical base in the root layout

Next.js documents `metadataBase` as the base URL for metadata fields that need an absolute URL. It is typically defined in the root `app/layout.js`, where it applies to URL-based metadata in that route segment and below. Replace the example host with the production canonical host; a preview domain in this value can publish the wrong preference across many routes. Next.js shallowly merges metadata from parent segments, so do not set `alternates.canonical` in the root layout: a route that defines no `alternates` of its own would inherit that value and declare itself a duplicate of it.

1. 01 An absolute [canonical URL](/glossary/canonical-url) ignores `metadataBase`.
2. 02 A relative URL-based metadata field without a configured `metadataBase` can cause a build error.
3. 03 Next.js normalizes duplicate slashes between the base and relative values. It treats a leading slash in a metadata path as relative to the base rather than replacing its path.
4. 04 Google recommends absolute URLs in `rel="canonical"` and says relative paths, although supported, can cause problems later. `metadataBase` makes the rendered tag absolute.

app/layout.tsx

```
import type { Metadata } from "next" export const metadata: Metadata = { metadataBase: new URL("https://www.example.com"), } export default function RootLayout({ children }) { return <html lang="en"><body>{children}</body></html> }
```

_02_Check it

## Generate canonical URLs for dynamic routes

A dynamic product, article, or category route should set its own canonical using its actual route data. If the page has [query parameters](/glossary/url-parameters) for tracking, sorting, or selecting content, decide whether those parameters represent a distinct page before emitting a canonical. Do not automatically canonicalize every query URL to the homepage. The code below uses Next.js 15 and later, where dynamic `params` are asynchronous; Next.js 14 and earlier use synchronous params, so follow the docs for your installed version.

Keep the canonical URL consistent with the URL the page actually serves after redirects. Generate it from trusted route data or a fixed base, not an incoming Host header that a request can change.

Page-specific canonical (Next.js 15+)

```
import type { Metadata } from "next" type Props = { params: Promise<{ slug: string }> } export async function generateMetadata({ params }: Props): Promise<Metadata> { const { slug } = await params const item = await getPublishedItem(slug) return { alternates: { canonical: \`/guides/${item.slug}\`, }, } }
```

_03_How it works

## Keep related signals aligned

Google recommends a `rel="canonical"` link on the canonical page itself and consistent links, redirects, and sitemap entries. It lists redirects and `rel="canonical"` as strong signals and sitemap inclusion as a weak one, and says not to name different canonical URLs for one page with different methods. Do not use robots.txt for canonicalization. A canonical preference is a hint, not a rule; Google may choose a different page for various reasons.

1. 1

### Inspect the production response

View source on representative static, dynamic, and localized routes. Confirm canonical links are absolute, use the preferred host, and are not duplicated by a plugin or custom head code.
2. 2

### Use URL Inspection

Check how Google sees an affected URL, including which canonical it selected. If that differs from your declared canonical, check redirects, page equivalence, sitemap, and internal links before changing metadata.
3. 3

### Retest after deployment

Inspect again after the deployment and allow Google to recrawl the updated output. Google has to recrawl the page before it can see a changed canonical.

Check canonical signals together
| Signal | What to compare | Good result |
| Canonical link | [Rendered HTML](/glossary/rendered-html) on each route | One absolute canonical per page |
| Redirects | Old aliases and [trailing slash](/glossary/trailing-slash) behavior | Redirects land on the canonical URL |
| [Internal links](/glossary/internal-links) | Navigation and content links | Link to the canonical URL directly |
| Sitemap | Published URL list | Lists canonical URLs, not tracking or redirect URLs |
| hreflang | Localized route alternates | Each locale canonical points to its own language version |

For route discovery and localized URLs, see [Next.js XML sitemaps](/seo/nextjs/xml-sitemap), the [hreflang guide](/glossary/hreflang), and the [canonical URL glossary](/glossary/canonical-url).

Sources · 6

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- nextjs.org
- google.com

1. 01 [generateMetadata | Next.js Documentation](https://nextjs.org/docs/app/api-reference/functions/generate-metadata) nextjs.org · checked 2026-10-24
2. 02 [generateMetadata | Next.js 14 Documentation](https://nextjs.org/docs/14/app/api-reference/functions/generate-metadata) nextjs.org · checked 2026-10-24
3. 03 [generateMetadata | Next.js 15 Documentation](https://nextjs.org/docs/15/app/api-reference/functions/generate-metadata) nextjs.org · checked 2026-10-24
4. 04 [How to specify a canonical with rel=canonical and other methods | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls) developers.google.com · checked 2026-10-24
5. 05 [What is canonicalization | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/canonicalization) developers.google.com · checked 2026-10-24
6. 06 [Create and submit a sitemap | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap) developers.google.com · checked 2026-10-24

Questions

## Asked a lot.

3 questions people ask next, answered from the sources on this page.

_01_ How do I add a canonical URL in Next.js?

In the App Router, export metadata with `alternates.canonical`. Set `metadataBase` in the root layout if you want relative canonical paths to resolve to the production host.

_02_ Why is Next.js generating a wrong canonical host?

Check `metadataBase` in the root layout and confirm it is set to the preferred production host rather than a preview or request-derived domain.

_03_ Does a canonical tag force Google to use that URL?

No. Google treats canonical annotations as signals and may choose another URL based on redirects, internal links, sitemap entries, and page content.

## Keep learning

[All platform guides](/seo)

[Learn Next.js SEO Frameworks](/seo/nextjs) [Related Canonical URL Crawling and indexing](/glossary/canonical-url) [Read next Next.js XML sitemap Frameworks](/seo/nextjs/xml-sitemap) [Do Run a free site audit Free, about two minutes](/site-audit)

More in Next.js SEO
[Next.js 404 page](/seo/nextjs/404) [Next.js AI crawlers](/seo/nextjs/ai-crawlers) [Next.js canonical tags](/seo/nextjs/canonical-tags) [Next.js Google Analytics](/seo/nextjs/google-analytics) [Next.js image SEO](/seo/nextjs/image-seo) [Next.js lazy loading](/seo/nextjs/lazy-loading) [Next.js noindex](/seo/nextjs/noindex) [Next.js redirects](/seo/nextjs/redirects) [Next.js robots.txt](/seo/nextjs/robots-txt) [Next.js structured data](/seo/nextjs/structured-data) [Next.js title and meta description](/seo/nextjs/title-and-meta) [Next.js XML sitemap](/seo/nextjs/xml-sitemap)

Terms on this page
[Canonical URL](/glossary/canonical-url) [URL parameters](/glossary/url-parameters) [Rendered HTML](/glossary/rendered-html) [Trailing slash in URLs](/glossary/trailing-slash) [Internal links](/glossary/internal-links) [Hreflang](/glossary/hreflang)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
