Set canonical metadata and locale alternatives
Give each page a meaningful identity
A document title identifies a page in the browser and can help search engines select a search-result title. A short description summarizes the content; engines can choose different snippets. A canonical URL indicates the preferred representative of similar URLs, not a command that guarantees selection. Use the same preferred URL in links and sitemaps, and avoid competing canonical declarations. Generate it from an approved origin and the public route record, not from arbitrary request headers or a tracking query string.
import {resolvePage} from './routes.mjs';export const origin = 'https://seed-library.example';export function metadata(path) { const {page} = resolvePage(path); if (!page) return null; return {title:page.title+' | Seed library', description:page.description, canonical:new URL(page.path, origin).href};}import React from 'react';import {metadata} from './metadata.mjs';export default function GuideMetadata({path}) { const meta = metadata(path); if (!meta) return <><title>Guide not found | Seed library</title><meta name="robots" content="noindex" /></>; return <><title>{meta.title}</title><meta name="description" content={meta.description} /> <link rel="canonical" href={meta.canonical} /></>;}For the seed storage guide, the title is “Store seeds in dry containers | Seed library” and its canonical is https://seed-library.example/guides/seed-storage. React 19 supports moving ordinary title, meta and canonical link elements into the head. React 18 projects normally need their framework metadata integration or a compatible head manager. On any version, choose one owner of route metadata; a framework may already manage it. The example returns a noindex instruction for missing pages, but the server still needs the proper HTTP status. Test initial HTML, route changes and absence of duplicate tags. Never initially emit noindex for a public route expecting a client effect to remove it later.
Regional alternatives are not duplicate content factories
If genuine regional variants exist, use full URLs and reciprocal hreflang references including each page itself. Each version should offer meaningful regional content; choose a consistent canonical strategy for same-language near-duplicates. The following fixture assumes two genuinely distinct regional articles, each self-canonical. It is not a request to add regional ByteMind translations. If only one English page exists, omit unnecessary alternates. An optional x-default can identify a real fallback page.
// Hypothetical real regional versions, both English; not ByteMind locales.export const alternatives = [ {lang:'en-US', href:'https://seed-library.example/us/guides/seed-storage'}, {lang:'en-GB', href:'https://seed-library.example/gb/guides/seed-storage'}];export function alternateLinks() { return alternatives.map(({lang,href}) => `<link rel="alternate" hreflang="${lang}" href="${href}">`).join('\n');}Include the same two tags on both regional documents. The function only handles the fixed safe values shown, not arbitrary HTML attributes. Practice: describe why a tracking parameter should not become a new canonical URL. Framework-specific metadata, routing and cache implementation belong in the Next.js track.