JExcellence
JExcellence
Full-stack · Oldenburg
GUIDE · 5 MIN READ

How eight Next.js subpages named the home page as their canonical

In Next.js every subpage inherits the layout's canonical and hreflang. How that hit eight pages of jexcellence.de, and how to check it with one command.
Justin EiletzNovember 18, 2026

A subpage can look flawless in the browser and still name a different address than its own in the source. On 9 November 2026 that was true for eight pages of jexcellence.de, in German and in English. The four offer pages, the blog index, the imprint, the privacy notice and the terms all declared the home page as the address to index. Nothing of this was visible on the page.

What the HTML said

The page /de/mittelstand sent this line:

The hreflang entries pointed at /de and /en, the two home pages, and not at the German and English versions of the offer page. The English pages pointed at /en in the same way. The sitemap listed the same addresses as separate pages, so the sitemap and the page head contradicted each other.

Blog posts and the Datenschutz-Check were not affected. Both set their own canonical.

The cause sits in the layout

The layout at app/[locale]/layout.tsx defines the metadata for every page of a locale. In short:

That is correct for the home page. But Next.js hands metadata from a layout down to every page below it. A page whose generateMetadata returns no alternates of its own keeps the layout's value as it is. The eight pages set a title, a description and keywords, but no alternates. Each of them carried the home page's address.

The bug is a missing line, not a wrong one. No linter and no type check reports it.

Next.js merges metadata only one level deep

The `generateMetadata` documentation states the rule in its "Merging" section, and the copy shipped with Next.js 16.4.3 says the same: metadata from several segments is merged shallowly and duplicate keys are replaced. Nested fields such as openGraph and robots from an earlier segment are overwritten by the last segment that defines them.

Two traps follow from that:

  • The page omits a field: the layout's value stays. That is how the home page address reached the subpages.
  • The page sets a field: the layout's block is gone completely, not only the keys the page sets again.

The second trap: the share image

The second trap hit the same pages in a different place. The layout defines an openGraph block with site name, locale and share image. The offer pages and the blog index define their own block with title, description and type. Next.js replaces the block, so og:image, og:site_name and og:locale were missing there.

/de/mittelstand sent only og:title, og:description, og:type and og:url. A link to that page showed no preview image in a messenger. The fix for the five pages uses the same helper as below.

The fix: every page names itself

The solution is one small file, app/lib/pageMetadata.ts, with three functions. pageUrl builds the absolute address of a route in one locale. pageAlternates returns canonical and hreflang for the page itself:

pageOpenGraph rebuilds the whole Open Graph block, including site name, locale and image, because the layout cannot be relied on at that point.

In the page it is then one line:

The change touches 11 files and adds 144 lines, 42 of them for three tests of the helper. Since the fix of 9 November, /de/mittelstand names itself as canonical and its hreflang entries point at /de/mittelstand, /en/mittelstand and, as x-default, the German version. The blog index does the same.

The list of locales comes from the routing configuration, not from a second list kept by hand. When a locale is added, the entries are right without another change.

How to check your own site

One command is enough. It fetches the served HTML and prints the canonical line:

If it prints the home page address, you have the same bug. Check one page of each kind: an offer page, the blog index, a post and a legal page. For the language entries, replace canonical with alternate.

Read the served HTML, not the code. Nothing in the code of the eight pages was wrong.

What the fix does not promise

A canonical of its own tells search engines which page is meant. Google's own documentation calls it a hint, not a rule, and Google may pick a different page as canonical. Whether and when that shows in search results cannot be promised. A single search for one of the offers on jexcellence.de returned no result from the site before the fix. That is one observation, not a measurement, and it proves no connection.

My own review of jexcellence.de for the post on SEO and GEO audits did not list this point. That review found missing hreflang on blog posts, and the posts were fine afterwards. I had not read the source of each offer page. An audit of your site does exactly that, page by page. Request an audit.

CONTENTS
next.js
canonical
hreflang
open graph
seo
metadata
Did this article raise a question about a project of your own? A 30-minute conversation about it is free and non-binding.