Technical SEO in Next.js: metadata, sitemaps and structured data

A practical guide to technical SEO in Next.js: the Metadata API, canonical and hreflang tags, sitemap.ts, robots.ts and JSON-LD structured data, with code.

Web Dev7 min read

The Creativenoir team
On this page

Technical SEO in Next.js covers everything that helps search engines find, understand and display a site's pages correctly: titles and descriptions, canonical URLs, language versions, the sitemap, crawler rules and structured data. Next.js ships native tools for each of them. What remains is applying them consistently across the whole site.

This guide starts from our own website. At Creativenoir we moved creativenoir.ro from a static React app hosted on Hostinger to Next.js on Vercel, and the SEO difference was clear. A classic React app sends the browser an almost empty page, and the content appears only after JavaScript runs. Next.js delivers every page already rendered, with its title, description and content in the HTML. The code examples target the App Router and Next.js 16.

What technical SEO covers in a Next.js project

Technical SEO deals with the infrastructure under the content: whether pages can be crawled, indexed and interpreted without ambiguity. In a Next.js project it comes down to five pieces: metadata, canonical and hreflang, the sitemap, robots rules and structured data.

The framework handles a large part out of the box: server or build-time rendering, so crawlers get complete HTML, plus generation of the <head> tags. The team is responsible for defining the right values and applying them the same way on every page.

PieceFile or API in Next.jsWhat it solves
Title, description, Open Graphmetadata / generateMetadatawhat shows in Google and when shared
Canonical and hreflangalternatesduplicates and language versions
Sitemapapp/sitemap.tsthe list of pages to index
Crawler rulesapp/robots.tswhat can be crawled
Structured data<script type="application/ld+json">context about the page

The Metadata API: titles, descriptions and canonical URLs

The Metadata API is how Next.js generates <head> tags natively. You export a metadata object (for static pages) or a generateMetadata function (for pages that depend on data) from layout.tsx or page.tsx. It works in Server Components only.

metadataBase and title.template in the root layout

The base configuration lives in the root layout. metadataBase allows relative paths in every field that needs an absolute URL, and title.template appends the brand name to every page title automatically.

src/app/layout.tsx
import type { Metadata } from "next";
 
export const metadata: Metadata = {
  metadataBase: new URL("https://www.example.com"),
  title: {
    default: "Example — Web design studio",
    template: "%s | Example",
  },
  description: "Websites, apps and campaigns for growing businesses.",
  robots: { index: true, follow: true },
};

A page that exports title: "Contact" gets the title "Contact | Example". The template applies to child segments only: a page in the same segment as the layout does not inherit it, and title.absolute handles the special cases.

generateMetadata for dynamic pages

For articles, products or services, metadata depends on the page content. In Next.js 16, params is a Promise and has to be awaited first.

src/app/blog/[slug]/page.tsx
import type { Metadata } from "next";
import { getPost } from "@/lib/blog";
 
type Props = { params: Promise<{ slug: string }> };
 
export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { slug } = await params;
  const post = await getPost(slug);
  if (!post) return {};
 
  return {
    title: post.title,
    description: post.description,
    alternates: { canonical: `/blog/${slug}` },
    openGraph: {
      type: "article",
      title: post.title,
      description: post.description,
      publishedTime: post.date,
    },
  };
}

Next.js 16 uses streaming metadata: the page starts loading before generateMetadata finishes, and the tags may land in <body>. The Next.js documentation confirms that Googlebot reads them correctly. Crawlers that do not run JavaScript, such as Facebook's, are detected by user agent and still receive the metadata in <head>.

One function for every page

On a site with dozens of pages, the same metadata structure repeats: title, description, canonical, Open Graph, Twitter. On creativenoir.ro we gathered it into one shared function that takes only what differs between pages. As a result, no page ships without a canonical URL or a share description.

src/lib/page-metadata.ts
import type { Metadata } from "next";
 
export function pageMetadata({
  path,
  title,
  description,
}: {
  path: string;
  title: string;
  description: string;
}): Metadata {
  const socialTitle = `${title} | Example`;
  return {
    title,
    description,
    alternates: { canonical: path },
    openGraph: { title: socialTitle, description, url: path, type: "website" },
    twitter: { card: "summary_large_image", title: socialTitle, description },
  };
}
src/app/contact/page.tsx
import { pageMetadata } from "@/lib/page-metadata";
 
export const metadata = pageMetadata({
  path: "/contact",
  title: "Contact",
  description: "Tell us about the project and we will come back with next steps.",
});

Multilingual sites: getting hreflang right

Hreflang tells search engines that two pages carry the same information in different languages, so each visitor gets the right version in the results. In Next.js it is set through alternates.languages, and every page has to list all versions, itself included.

The common mistake is maintaining URL pairs by hand on every page. On creativenoir.ro, the Romanian version has no prefix and the English one lives under /en, with translated slugs. All pairs are defined in a single list that feeds hreflang, the sitemap and the language switch.

src/i18n/routes.ts
export const ROUTE_PAIRS = [
  { ro: "/", en: "/en" },
  { ro: "/despre", en: "/en/about" },
  { ro: "/servicii/web-design", en: "/en/services/web-design" },
];
 
const RO_TO_EN = new Map(ROUTE_PAIRS.map((p) => [p.ro, p.en]));
 
export function pageAlternates(roPath: string, lang: "ro" | "en") {
  const en = RO_TO_EN.get(roPath);
  return {
    canonical: lang === "en" && en ? en : roPath,
    languages: en ? { ro: roPath, en, "x-default": roPath } : undefined,
  };
}

The resulting HTML contains a link rel="alternate" hreflang="..." tag for each language, plus x-default, the version shown when the visitor's language matches none of them. A new English page means one new line in the list.

sitemap.ts and robots.ts

Next.js generates sitemap.xml and robots.txt from TypeScript files in app/. The advantage over static files: the page list is built from the same data as the site, so a new article shows up in the sitemap automatically.

What Google reads from a sitemap

From a sitemap, Google uses only the URL and lastmod. The official documentation states that priority and changefreq are ignored, and that lastmod counts only when it is consistently accurate, meaning it reflects the last significant change to the page. A single sitemap holds at most 50,000 URLs or 50 MB uncompressed.

In practice, lastmod should come from the content date: when the page was published or last updated. The build date changes with every deploy and says nothing about the content. priority and changefreq can stay for other search engines, but they do not influence Google.

A sitemap with language alternates

src/app/sitemap.ts
import type { MetadataRoute } from "next";
import { getAllPosts } from "@/lib/blog";
 
const BASE = "https://www.example.com";
 
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const posts = await getAllPosts();
 
  return [
    {
      url: BASE,
      lastModified: new Date("2026-10-01"),
      alternates: { languages: { en: BASE, ro: `${BASE}/ro` } },
    },
    ...posts.map((post) => ({
      url: `${BASE}/blog/${post.slug}`,
      lastModified: new Date(post.updated ?? post.date),
    })),
  ];
}

For sites with tens of thousands of pages, generateSitemaps splits the list into several files.

src/app/robots.ts
import type { MetadataRoute } from "next";
 
export default function robots(): MetadataRoute.Robots {
  return {
    rules: { userAgent: "*", allow: "/", disallow: ["/api/"] },
    sitemap: "https://www.example.com/sitemap.xml",
  };
}

robots.txt only controls whether crawlers can access a page. A page blocked there can still appear in Google if other sites link to it. To remove a page from the index, set robots: { index: false } in that page's metadata.

JSON-LD structured data

Structured data describes the page in a standard format (schema.org): who published it, when, what kind of page it is and where it sits in the site structure. Google uses it for rich results, and other search engines and AI assistants can use it as additional context.

Adding it in the App Router

The Next.js documentation recommends a <script type="application/ld+json"> tag rendered directly in page.tsx or layout.tsx. JSON.stringify does not guard against content that contains </script>, so the < character is replaced with its unicode equivalent.

src/components/json-ld.tsx
export function JsonLd({ data }: { data: Record<string, unknown> }) {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify(data).replace(/</g, "\\u003c"),
      }}
    />
  );
}
src/app/blog/[slug]/page.tsx
import { JsonLd } from "@/components/json-ld";
import { getPost } from "@/lib/blog";
import { notFound } from "next/navigation";
 
export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const post = await getPost(slug);
  if (!post) notFound();
 
  return (
    <article>
      <JsonLd
        data={{
          "@context": "https://schema.org",
          "@type": "BlogPosting",
          headline: post.title,
          datePublished: post.date,
          dateModified: post.updated ?? post.date,
          author: { "@type": "Organization", name: "Example", url: "https://www.example.com" },
        }}
      />
      <h1>{post.title}</h1>
    </article>
  );
}

For autocompletion and type checks while writing, the schema-dts package provides TypeScript types for every schema.org entity.

Which types are worth using in 2026

The useful types depend on what the page contains. The core rule in Google's guidelines: structured data describes only what the visitor sees on the page.

schema.org typeWhere to use itEffect in Google
Organizationhome pagebrand identification (logo, name, links)
BreadcrumbListall inner pagespage path shown in results
Article / BlogPostingarticlestitle, date, author, image
LocalBusinessbusinesses with a physical locationcontact details and opening hours
Productonline storesprice, availability, reviews

For Article, Google has no required properties. It recommends headline, image, datePublished, dateModified and author, where the author can be a person (Person) or an organization (Organization).

One important change: Google stopped showing FAQ rich results on May 7, 2026, for all sites. Existing FAQPage markup can stay without side effects, but it no longer adds expandable questions under the result. Google also states that AI Overviews and AI Mode need no special markup: what counts is indexing, clear content and structured data that matches the visible text.

Share images generated from code

The Open Graph image appears when a link is shared on Facebook, LinkedIn or WhatsApp. Next.js can generate it from JSX with ImageResponse, so every page automatically gets an image with its own title, in the site's visual identity.

src/app/blog/[slug]/opengraph-image.tsx
import { ImageResponse } from "next/og";
import { getPost } from "@/lib/blog";
 
export const size = { width: 1200, height: 630 };
export const contentType = "image/png";
 
export default async function Image({ params }: { params: Promise<{ slug: string }> }) {
  const post = await getPost((await params).slug);
 
  return new ImageResponse(
    (
      <div style={{ display: "flex", width: "100%", height: "100%", padding: 64, background: "#1C1C1C", color: "#ECE7DF", fontSize: 64, alignItems: "flex-end" }}>
        {post?.title}
      </div>
    ),
    size,
  );
}

Next.js adds the matching og:image tags on its own. The share images of the articles on this blog are generated with ImageResponse too, from a single shared template.

Checks before launch

A few simple checks catch most problems before Google indexes the site.

ToolWhat we check
view-source: in the browsertitle, meta description, canonical, hreflang in the delivered HTML
Rich Results Testrich result eligibility and JSON-LD errors
Schema Markup Validatorgeneral validity of the structured data
Google Search Consolesubmitted sitemap, indexed pages, URL inspection
/sitemap.xml and /robots.txtcorrect URLs, no 404 pages or redirects

A site built correctly on Next.js starts with a clear indexing advantage, but the result depends on consistency: the same metadata structure, the same language rules and a sitemap generated from the same data as the site. That is how we work on our web design and development projects and on the custom software we deliver.

Frequently asked questions

No. In the App Router, the Metadata API covers titles, descriptions, canonical URLs, hreflang, Open Graph and Twitter cards. Mixing next-seo with the Metadata API leads to duplicate tags, so we recommend the Metadata API only.

No. Google states in its official documentation that it ignores priority and changefreq. It uses lastmod, but only when the date consistently reflects the last significant change to the page.

Google stopped showing FAQ rich results on May 7, 2026, for all sites. Existing markup can stay without affecting visibility, but it no longer produces a visual result in Google. BreadcrumbList and Article remain useful.

Google states that AI Overviews and AI Mode have no additional requirements and no special schema.org markup. What matters is that the page can be indexed, the content is clear and the structured data matches the visible text.

Open the page source (view-source) and look for the title, meta description, link rel canonical and link rel alternate tags. For structured data, use the Rich Results Test and the Schema Markup Validator; for indexing, use URL Inspection in Google Search Console.

Sources

  1. Next.js — generateMetadata and the Metadata API
  2. Next.js — sitemap.xml
  3. Next.js — JSON-LD
  4. Google Search Central — Build and submit a sitemap
  5. Google Search Central — Article structured data
  6. Google Search Central — FAQ structured data (deprecated)
  7. Google Search Central — AI features and your website

Keep reading

Google Ads vs Meta Ads: Which One Fits Your Business

Google Ads or Meta Ads? We compare intent, cost per lead and lead quality, with examples from our own campaigns, and explain when we use each platform.

Google Ads7 min read

Why Visitors Leave Your Website: 7 Common Causes

Why visitors leave a website within seconds: design, speed, CTAs, forms and site structure. Common causes, research-backed figures and how we fix them.

Web Design8 min read

We put what we write here into practice.

Share what you have in mind and we will propose the right next steps for the business.

Request a quote
Request a quote