DocsGuides
SEO for launch pages
Sections render as server components, so search engines get the full text in the first HTML. The rest is a few Next.js files. This is what this site does.
Title, description and share cards
Give every page its own title, description and canonical URL, and set the Open Graph and Twitter fields so shared links show that page. This site uses one helper for it:
import type { Metadata } from "next";
export function pageMeta(title: string, description: string, path: string): Metadata {
return {
title,
description,
alternates: { canonical: path },
// Setting openGraph drops the root opengraph-image file, so point back at it.
openGraph: { title, description, url: path, type: "website", images: "/opengraph-image.png" },
twitter: { card: "summary_large_image", title, description, images: "/twitter-image.png" },
};
}
// app/pricing/page.tsx
export const metadata = pageMeta("Pricing | Acme", "Plans for teams of every size.", "/pricing");Set metadataBase in your root layout so these paths become absolute URLs.
One h1 per page
Heroes render an h1. If a page has a second hero, or its own heading above one, pass titleAs="h2". Other sections start at h2, so the outline stays in order.
Sitemap and robots
import type { MetadataRoute } from "next";
export default function sitemap(): MetadataRoute.Sitemap {
return ["/", "/pricing", "/changelog"].map((p) => ({ url: `https://example.com${p}` }));
}import type { MetadataRoute } from "next";
export default function robots(): MetadataRoute.Robots {
return {
rules: { userAgent: "*", allow: "/", disallow: ["/examples/"] },
sitemap: "https://example.com/sitemap.xml",
};
}Keep demo and preview pages out of search
This site's demo companies are fictional, so their layouts set robots to noindex and they are left out of the sitemap. Do the same for staging copies or pages with sample content.
export const metadata = { robots: { index: false, follow: true } };Structured data
A <script type="application/ld+json"> tag describes the page to search engines. This site adds a SoftwareSourceCode entry to each section page; for a product, SoftwareApplication or Product fit. See json-ld.tsx for a version that escapes its content safely.