zudo-doc
GitHub repository

Type to search...

to open search from anywhere

Routing Conventions

Created Apr 28, 2026Updated Nov 30, 2026Takeshi Takatsudo

How paths() enumerates routes in zfb from the page's content view, and where document bodies are prepared.

Copy Markdown manually
The full Markdown is selected. Use your device’s copy command or try Copy again.

In zfb, every dynamic or catchall page exports a paths() function that tells the build which concrete URLs to emit. This page explains how paths() works, what to put inside it, and what to avoid.

Pages read content from ctx.content

zfb passes every page-module function an explicit context as its last argument: paths(ctx), getStaticProps(ctx) and default(props, ctx). ctx.content is a ContentView: an immutable view of the content collections, bound to one content revision. There is no global collection accessor; a page reads content only through the view it receives.

// pages/docs/[[...slug]].tsx
import type {
  EntryMeta,
  PathsContext,
  PreparedEntry,
  StaticPropsContext,
} from "@takazudo/zfb/content";

type DocData = { title: string; draft?: boolean };

export async function paths({ content }: PathsContext) {
  const docs = await content.list<DocData>("docs");
  return docs
    .filter((entry) => !entry.data.draft)
    .map((entry) => ({
      params: { slug: entry.id.split("/") },
      props: { entry },
    }));
}

export async function getStaticProps({ content, props }: StaticPropsContext) {
  const { entry } = props as { entry: EntryMeta<DocData> };
  return { props: { prepared: await content.prepare<DocData>(entry.ref) } };
}

export default function DocsPage({ prepared }: { prepared: PreparedEntry<DocData> }) {
  const { Content } = prepared;
  return <Content />;
}
  • paths() lists metadata only. content.list(name) returns each entry's id, frontmatter data, format, path, digest and an opaque ref. It never compiles a body.

  • getStaticProps() receives the matched paths() props as ctx.props and returns { props }, which zfb spreads over them. Prepare the document there with content.prepare(entry.ref). The result carries the synchronous Content component and the document's headings.

  • Keep paths() props small. Pass the entry metadata or its id, not prepared documents.

  • content.readSource(ref) returns the raw text ({ raw, body }) when you need it without preparing the document.

Listing a collection

content.list(name) is asynchronous; await it inside an async paths().

import type { PathsContext } from "@takazudo/zfb/content";

export async function paths({ content }: PathsContext) {
  const docs = await content.list<{ title: string; draft?: boolean }>("docs");
  return docs
    .filter((entry) => !entry.data.draft)
    .map((entry) => ({
      params: { slug: entry.id.split("/") },
      props: { title: entry.data.title },
    }));
}

The array is frozen, and the same view returns the same array for a collection. zfb memoizes paths() results per route and content revision. If you derive your own indexes from the lists, key their caches on the list arrays themselves (for example a WeakMap keyed by the array), and read the lists on every request. Do not key a shared cache on content.revision alone: two independent content providers can report the same revision string. In dev, zfb records which collections a page read from those calls; a value cached at module level and never read again is invisible to that tracing.

Do not fetch live data inside paths()

paths() is async so that it can await the content view. Do not use that to fetch remote data:

// ❌ Anti-pattern — live fetch inside paths()
export async function paths() {
  const res = await fetch("https://api.example.com/items");
  const items = await res.json();
  return items.map((item) => ({ params: { slug: item.id } }));
}

This pattern causes several problems:

  • Non-determinism — the remote API may return different data on each build run

  • Reproducibility — the same commit can produce different HTML output

  • Offline breakage — builds fail in air-gapped environments or CI with no network access

  • Build latency — every build pays for a network round-trip during route enumeration

The content layer exists precisely to avoid this: fetch once before the build, store the result as content, and read it through the content view.

Package route injection and shadowing

The real pages/docs/[[...slug]].tsx doc-route stub does not hand-roll the listing like the example above. It loads the route context and chrome for the request's content view with createChromeLoader(), enumerates with routeCtx.buildDocRouteEntries(), and prepares the document with the package's getDocPageStaticProps(). A generated project normally doesn't author this file at all — see below.

With packageOwnedRoutes (the default) set to true, the @takazudo/zudo-doc routes plugin injects the documentation routes at build time. That includes /docs/[[...slug]], its locale and version variants, and the tag and version routes. A generated project therefore ships almost no pages/ files of its own.

A project route still has priority over an injected route at the same path. When that happens, the build log reports:

shadowed by a user pages/ route (user wins); skipping

The user file is used and the package route is not injected. Use this intentionally when a route needs a project-specific implementation.

The / route is different. zfb does not permit injecting /, so the scaffold's pages/index.tsx is a one-line re-export of @takazudo/zudo-doc/routes/index. It provides the home page; it is not an example of route shadowing.

The self-contained documentation-route stubs in the scaffold are retained as explicit host-owned seams, not because injected dynamic routes fail in dev. zfb 2.13.1 renders those injected routes in both dev and build. The / route remains a separate exception because zfb does not permit injecting /.

When you customize a doc-route stub that shadows an injected route, it must also import chromeBindings from virtual:zudo-doc-chrome-bindings and pass it to createChromeLoader. Otherwise the chromeBindingsModule channel is severed for your doc pages. See Custom Components for the complete stub-threading patterns.

Migration from Astro's getStaticPaths

If you're migrating a project from Astro, paths() replaces getStaticPaths(). The main difference is that paths() reads data only through ctx.content, so all data must be pre-loaded into content collections before the build runs.

Astro's getStaticPaths() accepted any async operation. Patterns like the following were common:

// ❌ Astro — before migration
// pages/docs/tags/[tag].tsx
export async function getStaticPaths() {
  const res = await fetch("https://api.example.com/tags");
  const tags = await res.json();
  return tags.map((tag: { slug: string }) => ({
    params: { tag: tag.slug },
  }));
}

In zfb this becomes a two-step process.

Step 1 — Move the fetch into a build-time generator script. Run it before zfb build and write its output into a content collection or a static JSON file:

// scripts/fetch-tags.ts — run as a pre-build step
import { writeFileSync, mkdirSync } from "fs";

const res = await fetch("https://api.example.com/tags");
const tags = await res.json();

mkdirSync("src/content/tags", { recursive: true });
for (const tag of tags) {
  writeFileSync(
    `src/content/tags/${tag.slug}.json`,
    JSON.stringify(tag),
  );
}

Step 2 — Read the pre-fetched data inside paths() through ctx.content:

// ✅ zfb — after migration
// pages/tags/[tag].tsx
import type { PathsContext } from "@takazudo/zfb/content";

export async function paths({ content }: PathsContext) {
  const tags = await content.list<{ label: string }>("tags"); // reads the pre-generated content
  return tags.map((tag) => ({
    params: { tag: tag.id },
    props: { label: tag.data.label },
  }));
}

export default function TagPage({ label }: { label: string }) {
  return <h1>{label}</h1>;
}

For data that never changes between deploys (e.g. an initial dataset committed to the repo), you can skip the generator script entirely and author the JSON files directly in src/content/.

Quick comparison

Astro getStaticPathszfb paths
Signatureasync function getStaticPaths()async function paths(ctx)
Data accessawait getCollection(...) or await fetch(...)await ctx.content.list(...); bodies via ctx.content.prepare(ref) in getStaticProps
Live HTTP fetchAllowed (not recommended for SSG)Move to a pre-build step
Return shape{ params, props }[]{ params, props }[]
Draft filteringFilter in getStaticPathsFilter in paths()

See also

  • i18n — per-locale route enumeration with paths()

  • Versioning — versioned docs and their route conventions

Revision History

Takeshi TakatsudoCreated: 2026-04-28T20:38:07+09:00Updated: 2026-11-30T11:44:24Z

AI Assistant

Ask a question about the documentation.

Preview theme

Loading theme previews…