<Head>
import { Head } from '@qatjs/head'
export default function Product({ data }) {
return (
<article>
<Head>
<title>{data.name} · Shop</title>
<meta name="description" content={data.blurb} />
<link rel="canonical" href={`https://shop.example/p/${data.id}`} />
</Head>
<h1>{data.name}</h1>
</article>
)
}
- The elements move into
document.head and stay reactive.
- Deduplicated: one
title; meta by name or property; link by rel + href. For each,
the most recently mounted <Head> wins — a page's over its layout's — and unmounting restores the
previous one, or the page's own from index.html. Two links with one rel and different hrefs
are two links: a <link rel="canonical"> in index.html stays beside a page's own. Set the
canonical in <Head> alone, the layout's as the default.
- A
<Head> inside a hidden keep page drops out until the page is shown again.
- On a server-rendered route the winners are written into
<head>, and the browser's <Head>
takes them over when the page resumes (server rendering).
{if} and {switch} inside <Head> choose their elements once, when the <Head> is set up,
on the server and in the browser. The elements' attributes stay reactive; for a choice that
changes later, put the <Head> itself inside the {if}:
import { Head } from '@qatjs/head'
export default function Doc({ data }) {
return (
<Head>
<title>{data.title}</title>
{if (data.slug === 'README')}
<link rel="canonical" href="/docs" />
{else}
<link rel="canonical" href={`/${data.slug}`} />
{/if}
</Head>
<article innerHTML={data.html} />
)
}