Canonical through a single Seo component
A relative canonical resolves differently depending on the requested URL, which is exactly the ambiguity a canonical exists to remove. Check meta-canonical-absolute
import Head from "next/head";
import { canonicalUrl } from "@/lib/seo";
// One component owns the head. Emitting tags from more than one place is how a
// page ends up with two canonicals, because next/head does not deduplicate
// custom link elements.
export function Seo({ title, description, path }: { title: string; description: string; path: string }) {
const url = canonicalUrl(path);
return (
<Head>
<title>{`${title} | Acme`}</title>
<meta content={description} name="description" />
<link href={url} rel="canonical" />
<meta content={url} property="og:url" />
<meta content="summary_large_image" name="twitter:card" />
</Head>
);
}