Page Metadata

Page Metadata

Drive the document head from your page modules.

Updated: 2026-07-26

The meta export

Export meta from a page and Karui renders it into the head. Every field is optional; omit title and it falls back to one derived from the route path.

src/pages/docs/[slug].tsx
export const meta = {
  title: 'Docs',
  description: 'How Karui routing works',
  canonical: 'https://example.com/docs',
  robots: 'index,follow',
  lang: 'en',
  og: { type: 'article', image: 'https://example.com/card.png' },
  twitter: { card: 'summary_large_image' },
  meta: [{ name: 'author', content: 'Rigby Foundation' }],
  link: [{ rel: 'alternate', hreflang: 'de', href: '/de/docs' }],
};

Open Graph defaults

og:title, og:description, and og:url default to your title, description, and canonical, so most pages set only the three fields they care about. Anything you put in og overrides the derived value.

Metadata from loader data

Export a function instead of an object to build metadata from the resolved route context. Loaders run first, so ctx.data is available.

tsx
export const meta = (ctx) => ({
  title: `Post: ${ctx.data.title}`,
  description: ctx.data.excerpt,
  og: { image: ctx.data.coverUrl },
});

Document language

meta.lang rewrites the lang attribute on the html tag of your template, which matters for multilingual sites where the language is part of the route.