Page Router
Understand the renderer pages directory scanned by the NarraLeaf CLI.
The CLI scans renderer/pages and generates the route tree passed to render(). Pages are rendered inside the NarraLeaf-React player through the generated RootPages component.
File Rules
index.tsx,index.jsx,index.ts, orindex.jshandles the default page for a directory.layout.tsx,layout.jsx,layout.ts, orlayout.jswraps child pages in that directory.error.tsx,error.jsx,error.ts, orerror.jsat the pages root becomes the global error fallback.- Other files become pages by filename.
- Directory names like
[name]become slug parameters.
renderer/pages
├── index.tsx
├── save.tsx
├── settings.tsx
├── error.tsx
└── gallery
├── layout.tsx
├── index.tsx
└── [id].tsxLayouts
A layout module exports a React component that accepts children.
import type { ReactNode } from "react";
export default function GalleryLayout({ children }: { children: ReactNode }) {
return <section>{children}</section>;
}Pages
A page module exports a React component.
import { useSavedGames } from "narraleaf/renderer";
export default function SavePage() {
const { results } = useSavedGames();
return <pre>{JSON.stringify(results, null, 2)}</pre>;
}Slugs
Directory names that start with [ and end with ] are treated as slug segments. The accepted slug name characters include letters, numbers, underscore, hyphen, and common CJK characters.
renderer/pages/gallery/[id].tsxRoute Conflicts
A directory can use either:
- a local
indexfile, or - a sibling file with the same name as the directory.
Do not use both for the same route.
renderer/pages/gallery.tsx
renderer/pages/gallery/index.tsxThe CLI treats this as a routing conflict because both files would handle /gallery.