Examples
Practical examples. Live demos.
Pick an example to open it full screen, with the live preview and its source side by side.
Pick an example to open it full screen, with the live preview and its source side by side.
The post page exports a load() that runs before the page is built. Watch router.pending while it waits, and the error state with Retry when it throws on the broken post.
nuclo-router is not part of nuclo and must be installed:npm install nuclo nuclo-router// Post.ts: a page with a load(). It runs before the page is built, on every // visit, and whatever it returns arrives as `data`. While it runs, // router.pending is true and the previous page stays on screen. import type { DataLoader, PageProps, RouteContext } from "nuclo-router"; interface Post { title: string; body: string } const wait = (ms: number) => new Promise((r) => setTimeout(r, ms)); export const load: DataLoader<Post> = async (ctx) => { await wait(700); // a slow API if (ctx.params.slug === "broken") throw new Error("post not found"); const title = ctx.params.slug.replace(/-/g, " "); return { title, body: "Loaded by load() before the page was built." }; }; export default function Post( _ctx: RouteContext, { data }: PageProps<Post>, ) { return article(h1(data.title), p(data.body)); }