PAS7 Studio
Back to all articles

Next.js sitemap hreflang for App Router and static export: @pas7/nextjs-sitemap-hreflang

A practical guide to Next.js sitemap hreflang for App Router and static export: generate hreflang alternates and x-default, inject or fix sitemap.xml, validate hreflang in CI, and support mixed content pipelines.

Best forFrontend engineersTechnical SEO engineersNext.js teams shipping multilingual sitesTech leads standardizing sitemap validation in CI
Editorial cover showing a Next.js sitemap workflow with hreflang alternates, x-default, App Router MetadataRoute.Sitemap, and XML validation in CI

The package is easiest to understand as a sitemap workflow tool, not just a helper function. It covers generation, XML patching, validation, and mixed routing in one place. [1][2][3]

Build hreflang alternates for App Router MetadataRoute.Sitemap. [1][4]
Inject or fix hreflang directly in generated sitemap.xml. [1]
Validate sitemap hreflang in CI instead of checking XML by hand. [1][3]
Support mixed content pipelines from .ts, .json, .md/.mdx, or CMS data. [1]
Handle hybrid routing patterns such as prefix, suffix, and locale-segment in one site. [1][2]
Return machine-readable JSON reports and explicit exit codes for CI. [1][3]

The hard part is usually not creating one multilingual sitemap. The hard part is keeping alternate language URLs correct as the site grows. Static pages may follow one locale pattern, content hubs another, and detail pages a third. In practice, a single multilingual site often mixes homepage routing, localized hubs, and locale-segment detail pages. [1][2]

Next.js App Router gives you a clean way to generate sitemap entries through MetadataRoute.Sitemap, but it does not solve every hreflang routing rule for you. The official docs define the sitemap file convention and output shape, while a package like this fills the gap around alternate-language linking and route-aware validation. [1][4]

Google’s hreflang guidance also raises the bar a bit. Alternate URLs should be fully qualified, pages should reference themselves and their alternates, and x-default can be useful for language-neutral fallback pages. That is manageable in a small site, but easy to get wrong when URLs come from multiple pipelines. [5][6]

The real issue

Sitemap hreflang gets brittle when routing rules live in several places and multilingual alternates stop matching the real site structure. [1][2][5]

The quickest entry point is App Router generation with a routing helper and withHreflangFromRouting.

01

Define the routing model

The package includes helpers such as routingPrefixAsNeeded and routingPAS7 to describe how locales appear in URLs. [1][2]

02

Build a normal MetadataRoute.Sitemap entry list

You start from standard sitemap entries such as /blog or /about, then let the package derive hreflang alternates from the routing model. [1][4]

03

Wrap entries with hreflang generation

The README quick start uses withHreflangFromRouting(entries, routing, { baseUrl, ensureXDefault: true }), which keeps the sitemap generation close to normal App Router code. [1]

Why this feels clean

The package stays close to native App Router sitemap generation instead of forcing a separate XML-only workflow from the start. [1][4]

The routing helpers are where the package becomes more than a small hreflang wrapper.

Comparison pointPatternTypical use
Prefix as neededHome pages and simple localized routes such as /, /uk, /deUseful when the default locale should stay unprefixed and other locales need a prefix
Suffix localeContent hubs and static pages such as /blog/uk or /contact/ukUseful when hub pages follow a suffix locale pattern instead of a prefixed path
Locale segmentDetail pages such as /blog/en/slug or /blog/uk/slugUseful when content entries need stable locale-aware detail routing
Mixed prefix pagesOptional exceptions such as /uk/about alongside other route stylesUseful when one site mixes several legacy or section-based routing rules

Where the value shows up

If your site mixes route patterns, the package gives you one place to describe that logic instead of hardcoding alternates page by page. [1][2]

A lot of teams do not generate sitemap entries directly from one TypeScript array. They already have manifests, frontmatter exports, or CMS-normalized data.

That image support is a nice detail because it matches how many modern static sites actually store content. A post may have one main cover plus several nested screenshots. The docs show how to extract both into the sitemap entry rather than only keeping the top-level URL. [1]

A minimal example from the README looks like this:

TS
import { createSitemapEntriesFromManifest } from "@pas7/nextjs-sitemap-hreflang";

const entries = createSitemapEntriesFromManifest(blogManifest, {
  baseUrl: "https://pas7.com.ua",
  sectionPath: "/blog",
  defaultLocale: "en",
  routeStyle: "locale-segment",
});

Manifest helper

createSitemapEntriesFromManifest is meant for pipelines that already output slug, locales, and date fields. That keeps sitemap generation aligned with existing content manifests instead of duplicating route logic. [1]

Mixed source support

The package explicitly supports .ts, .json, .md/.mdx, and CMS-driven content pipelines, which makes it easier to use across different content sources in one Next.js project. [1]

Images in sitemap entries

The helper can also include images through imagesFor, which is useful when sitemap entries should carry image URLs from nested content fields like hero covers and section screenshots. [1]

Why this matters

The package fits better into real content systems because it can start from the manifests and data sources teams already have. [1]

The CLI is small, but the split between check and inject is useful.

Use check

Best when you want validation in CI: missing alternates, XML issues, origin-policy checks, and machine-readable reports with --json. [1][3]

Use inject

Best when the site already emits a sitemap file and you want to inject or fix hreflang directly in generated XML during a postbuild step. [1]

Use --prefer when the source file location matters

The CLI can auto-detect public/sitemap.xml, out/sitemap.xml, or sitemap.xml, but explicit preference is safer when the pipeline has more than one candidate output. [1]

Do not skip report output in CI

The JSON report format is stable and includes issue codes, entry URLs, messages, suggestions, summary counts, input path, and timing. That makes debugging much easier than parsing console logs. [1][3]

Practical rule

Use check when the goal is to fail CI cleanly. Use inject when the goal is to patch an already generated sitemap.xml file. [1][3]

The exit codes and JSON format make the package easier to automate than tools that only print human-oriented warnings.

This is one of the quieter strengths of the package. The CLI does not just say that validation failed; it distinguishes missing input, XML failures, and validation errors. That makes pipeline behavior much easier to reason about. [1]

The report format is similarly practical: ok, issues[], summary.byCode, inputPath, and timingMs. Those fields are exactly the kind of contract that CI jobs or dashboards can consume without guesswork. [1][3]

0

OK. Validation passed. [1]

2

Validation errors, including --fail-on-missing failures. [1]

4

Input file not found. [1]

5

Invalid XML input. [1]

What this adds

The package is built not only for generation, but for predictable automation around sitemap hreflang checks. [1][3]

The package is direct, but multilingual sitemap workflows still go wrong in familiar ways.

Assuming one route pattern fits every part of the site. Mixed routing is common, and the package is designed for that reality. [1][2]

Treating x-default as optional noise everywhere. In some multilingual setups it is useful as the language-neutral fallback, and the package can enforce it with ensureXDefault. [1][6]

Keeping sitemap alternates separate from the content pipeline. That usually leads to stale locale clusters or missing entries. [1]

Running next build without a follow-up validation step. Static export and generated XML both benefit from explicit checks in CI. [1][3]

Ignoring Google’s hreflang rules around fully qualified alternate URLs and reciprocal language variants. The XML may look fine while still being structurally incomplete. [5][6]

Healthy expectation

Sitemap hreflang becomes much more reliable when routing, alternates, and CI validation all follow the same rules. [1][2][3][5]

These official sources support the package behavior, Next.js sitemap context, and hreflang guidance used in this article.

Reviewed: 15 Mar 2026Applies to: Next.js App Router projectsApplies to: Next.js static export workflowsApplies to: Multilingual and international SEO setupsApplies to: Manifest-based content pipelines

The difficult part is usually not adding hreflang once. It is keeping alternates, route patterns, XML output, and CI checks aligned as the site grows.

PAS7 Studio can help turn that into a repeatable multilingual SEO pipeline with cleaner routing rules, safer sitemap validation, and fewer hreflang surprises after deployment.

Related Articles

growth

AI SEO / GEO in 2026: Your Next Customers Aren’t Humans — They’re Agents

Search is shifting from clicks to answers. Bots and AI agents crawl, cite, recommend, and increasingly buy. Learn what AI SEO / GEO means, why classic SEO is no longer enough, and how PAS7 Studio helps brands win visibility in the agentic web.

blogs

The most powerful Apple chip yet? M5 Pro and M5 Max are breaking records

A data-backed March 2026 analysis of Apple M5 Pro and M5 Max. We break down why these chips can credibly be called Apple's most powerful pro laptop silicon, how they compare with M4 Pro, M4 Max, M1 Pro, M1 Max, and how they stack up against Intel and AMD laptop rivals.

telegram-media-saver

Automatic Tagging & Search for Saved Links

Integrate with GDrive/S3/Notion for automatic tagging and fast search via search APIs

services

Bot Development & Automation Services

Professional Telegram bot development and business process automation: chatbots, AI assistants, CRM integrations, workflow automation.

Professional development for your business

We create modern web solutions and bots for businesses. Learn how we can help you achieve your goals.