⚡ Dinou Complete Cheatsheet
At-a-glance high-density desktop reference for file conventions, dynamic route syntax, server lifecycle contracts, client navigation hooks, and architectural decision matrices.
This cheatsheet provides concise signatures and decision tables. Full implementations are documented in the API Reference.
1. File Conventions CheatsheetFilesystem
Directories inside src/ directly map to URL paths. Standardized file names define UI leaves, layout shells, and decoupled server contracts.
Route Components & Lifecycles
| Filename | Role | Scope | Key Responsibility |
|---|---|---|---|
| page.{tsx,jsx,ts,js} | Route Page UI | Universal | Primary UI component rendered for the route segment. Receives params and any props returned by page_functions getProps(). |
| layout.{tsx,jsx,ts,js} | Layout Shell | Universal | Persistent UI wrapper preserving client state across child navigations. Receives children, params, sibling @slot props, and layout_functions getProps(). |
| @slot/page.{tsx,jsx,ts,js} | Parallel Slot UI | Universal | Parallel route rendered concurrently and injected as the named slot prop into the sibling layout.tsx. Supports isolated @slot/error.tsx containment. |
| error.{tsx,jsx,ts,js} | 500 Error Page | Universal | Error UI rendered when an unhandled exception occurs within this route or @slot subtree. Receives { error, params }. |
| not_found.{tsx,jsx,ts,js} | 404 Page | Universal | Rendered when no route matches, validateParams() returns false, or allowISG = false rejects an ungenerated path. Receives params and optional sibling getProps(). |
| page_functions.{ts,js,tsx,jsx,mjs} | Page Server Lifecycle | Server Only | Decoupled server contract for page.tsx: getProps, revalidate, ppr, getStaticPaths, getCacheTags, allowISG, validateParams. |
| layout_functions.{ts,js,tsx,jsx,mjs} | Layout Server Lifecycle | Server Only | Decoupled server contract for layout.tsx: independent getProps, revalidate, ppr, getStaticPaths, getCacheTags, allowISG, and validateParams. |
| dinou.config.{ts,mjs,js,cjs} | Project Config (Root) | Build / Server | AOT-bundled global config via defineConfig() (reactCompiler, reactStrictMode, ppr, allowISG, storage, setupFiles, assetExtensions, plugins). Optional root dinou.setup.{ts,mjs,js} runs pre-boot polyfills. |
src/blog/[slug]/not_found.tsx intercepts 404s before the root src/not_found.tsx.Layout Control Flags (Empty Files)
Create these empty files (zero bytes, no extension) inside a route directory to modify layout inheritance without writing custom wrapper logic:
| Flag File | Target | Architectural Effect |
|---|---|---|
| no_layout | page.tsx | Renders the page completely bare, bypassing all parent layouts. Ideal for print templates, popups, or embeddable iframes. |
| reset_layout | layout.tsx | Resets the layout stack. Discards all ancestor layouts; this folder's layout.tsx becomes the isolated new Root Layout for this branch. |
| no_layout_error | error.tsx | Renders the segment's 500 error page without any surrounding layout shells. |
| no_layout_not_found | not_found.tsx | Renders the segment's 404 not found page without any surrounding layout shells. |
Route Escaping (_prefix)
Any directory prefixed with an underscore (_folder) is completely ignored by Dinou's router, bundlers, and route type generator.
When to use Underscore Folders
components/, hooks/, utils/) do NOT require an underscore prefix; Dinou only treats a folder as a route if it contains a page.* file. Use _ exclusively to quarantine legacy or backup folders containing page.* files (e.g., src/_archived-v1/page.tsx).2. Route Syntax & TypesType Safety
Dinou provides zero-runtime type safety by inferring route parameter types directly from folder bracket naming conventions.
Route Patterns & Inferred Params
| Folder Pattern | Example URL | Inferred params Type | Behavior |
|---|---|---|---|
| /about | /about | {} | Static segment. Exactly matches literal path. |
| /blog/[slug] | /blog/hello-world | { slug: string } | Single required dynamic parameter. |
| /docs/[...slug] | /docs/api/routing | { slug: string[] } | Catch-all. Matches 1 or more trailing segments. |
| /shop/[[...slug]] | /shop, /shop/shoes/nike | { slug: string[] } | Optional catch-all. Matches 0+ segments; normalized to [] at root (input params in <Link>/getStaticPaths stays optional). |
| /dash/[[tab]] | /dash, /dash/billing | { tab?: string } | Optional single parameter (strict No-Gap rule for chained optional segments). |
| /(auth)/login | /login | {} | Route group. Organizes files and scoped layouts without adding a URL segment. |
| /dash/@analytics | /dash (injected slot) | Inherits ancestor params | Parallel slot. Rendered into sibling layout.tsx as analytics?: ReactNode. |
Type-Safe Routing Helpers (dinou & ./dinou)
| Helper / Import | TypeScript Signature | Purpose | API Ref |
|---|---|---|---|
| PageProps<T, TProps?> | { params: RouteParams<T> } & TProps | Props for page.tsx (merges getProps() return via TProps). Query params use useSearchParams(). | Docs |
| LayoutProps<T, TProps?> | { children: ReactNode; params: LayoutParams<T> } & LayoutSlots<T> & TProps | Props for layout.tsx (including intermediate layouts); auto-injects sibling @slot props and layout_functions props. | Docs |
| SlotProps<T> & NotFoundProps<T, TProps?> | { params: SlotParams<T> } / { params: RouteParams<T> } & TProps | Dedicated types for @slot/page.tsx parallel slots and scoped not_found.tsx boundaries. | Docs |
| ErrorProps<T> | { error: Error; params: ErrorParams<T> } | Props for error.tsx and @slot/error.tsx boundaries (runtime delivers sanitized error details). | Docs |
| PageFunctions / LayoutFunctions | PageFunctions<T, TProps?> / LayoutFunctions<T, TProps?> | Typed contract interfaces for page_functions.ts and layout_functions.ts exports (getProps, getStaticPaths, etc.). | Docs |
| RouteParams<T> | Extracted parameter dictionary from generated registry or literal pattern | Typed params argument for getProps, getCacheTags, or validateParams. | Docs |
| DinouRoute & DinouLinkTarget | Concrete routes + dynamic patterns ("/blog/[slug]") + relative from | Level 1 type safety: IDE autocomplete & validation for <Link>, router.push(), and params interpolation. | Docs |
| DinouRoutePattern & Segments | DinouRoutePattern, DinouLayoutPattern, DinouSlotPattern, DinouErrorPattern | Level 2 type safety: generic pattern constraints across pages, layouts, parallel slots, and error/404 boundaries. | Docs |
| Contextual "./dinou" | import { PageProps, LayoutProps, Link, useRouter } from "./dinou" | Zero-boilerplate (Recommended): auto-binds route params, sibling @slots, and relative from origin to the current folder. | Docs |
3. Server Lifecycle ContractsServer Only
Contracts declared in page_functions.ts (or layout_functions.ts). Executed exclusively on the server, completely decoupled from React render passes.
Exported Contracts Table
| Exported Contract | Signature | Default | Execution & Purpose | API Ref |
|---|---|---|---|---|
| getProps(params) | (params) => Promise<T> | T | {} | Server data loader. Return value is directly passed as props to page.tsx or layout.tsx. | Docs |
| revalidate | number | false | (() => ...) | false (SSG) | Cache TTL in seconds. 0 (or < 1) = Dynamic SSR, >= 1 = ISR, false / omitted = Static SSG. | Docs |
| ppr | boolean | (() => boolean | Promise<boolean>) | config.ppr ?? false | Segment-isolated Partial Prerendering: pre-renders static shell and streams <Suspense> holes (does not inherit from parent layouts). | Docs |
| getCacheTags | string[] | ((params?) => string[] | Promise<string[]>) | [] | Associates cache tags (constant array or function) with the route or layout for targeted invalidation via revalidateTag(tag). | Docs |
| getStaticPaths | StaticPathItem[] | (() => StaticPathsResult) | [] | Pre-generates dynamic parameter values/objects at build time (constant array or function) across page_functions and layout_functions ([p], [[p]], [...s], [[...s]]). | Docs |
| allowISG | boolean | (() => boolean | Promise<boolean>) | config.allowISG ?? true | When true, ungenerated dynamic paths render on-demand (ISG). When false, ungenerated paths return 404 on both HTML and SPA RSC fetches. | Docs |
| validateParams(params) | (params?) => boolean | Promise<boolean> | () => true | Authoritative root-to-child gatekeeper. Returning false vetoes cached HTML/RSC and terminates with 404 before getProps(). | Docs |
Revalidation Modes (SSR vs ISR vs SSG)
| Export Value | Rendering Mode | Cache Behavior | Ideal Use Case |
|---|---|---|---|
| export const revalidate = 0; | Dynamic SSR | Evaluated fresh on every HTTP request (any value < 1). Never cached in static storage. | User accounts, checkout pages, real-time analytics. |
| export const revalidate = 60; | ISR (Regeneration) | Served from cache for N seconds (>= 1). Next visit serves stale cache and triggers background re-generation. | E-commerce product pages, news feeds, search result pages. |
| export const revalidate = false; | Static (SSG) | Default when omitted. Prerendered at build time and cached indefinitely until purged via on-demand invalidation. | Marketing landing pages, documentation, blog posts. |
5. Server Primitives & Cachedinou & dinou/server
Server-side context providers, micro-ISR slot primitives, and cluster cache purge APIs.
Context, Config, Plugins & Cache Slots
| Export | Package | Signature | Purpose & Mechanics | API Ref |
|---|---|---|---|---|
| getContext() | dinou, dinou/server, dinou/config | () => RequestContextStore | Synchronous AsyncLocalStorage access (never null): req (cookies, headers, path, rawPath, isRscRequest), res, unified env (DinouEnv + KV/D1/R2), and ctx. | Guide API |
| <DinouCacheSlot> | dinou/server | id?, revalidate?: number | false, tag?, tags?, children | Micro-ISR server component. Caches an independent sub-tree (merges tag + tags; id defaults to first tag; children accepts JSX or async render fn). | Docs |
| noDynamic() | dinou, dinou/server, dinou/config | () => void | Call synchronously before first await to opt an enclosing <Suspense> boundary out of becoming a dynamic PPR hole, baking it into shell.html. | Docs |
| defineConfig(config) | dinou, dinou/config | (config: DinouConfig) => DinouConfig | Type helper for dinou.config.{ts,mjs,js,cjs} (reactCompiler, reactStrictMode, ppr, allowISG, storage, setupFiles, assetExtensions, plugins). | Docs |
| DinouPlugin | dinou, dinou/config | { name?, setupFiles?, onRequest?, configureServer? } | Universal request middleware (onRequest runs ahead of static/ISR/PPR caches and translates SPA redirects) + Node HTTP hooks (configureServer). | Docs |
| Storage Adapters | dinou/server | FileSystemStorage, RedisStorage, CloudflareKVStorage, DenoKVStorage, MemoryStorage | Pluggable ISR/ISG/PPR cache backends plus StorageAdapter base class, getStorageAdapter(), and setStorageAdapter(). | Docs |
On-Demand Cache Invalidation (dinou/server)
| Function | Target | Signature | Purge Effect | API Ref |
|---|---|---|---|---|
| revalidatePage(path) | Page Component Only | (path: string) => Promise<void> | Regenerates only the page's page.rsc and index.html (or shell.html), leaving parent layout.rsc untouched. | Docs |
| revalidateLayout(path) | Layout Segment Only (O(1)) | (path: string) => Promise<boolean> | Regenerates only layout.rsc in O(1) time (0 child pages executed); child index.html files lazily re-compose on demand. | Docs |
| revalidatePath(path) | Segment Layout + Page | (path: string) => Promise<void> | Regenerates both the segment's layout.rsc (if present) and its page.rsc + index.html (revalidateLayout + revalidatePage). | Docs |
| revalidateTag(tag) | Tags (Pages, Layouts & Slots) | (tag: string) => Promise<void> | Purges and regenerates all pages, layouts (O(1)), and <DinouCacheSlot> fragments tagged with the identifier (including id-only slots) across the cluster. All path-based helpers also accept relative paths ("./", "../...") inside Server Functions. | Docs |
6. CLI & Execution Modesdinou CLI
Unified CLI for multi-bundler development, multi-runtime AOT production builds, static export, type generation, ejection, and dual-mode additive vendoring.
Core CLI Commands (dinou)
| Command | Output / Runtime | Purpose | Guide |
|---|---|---|---|
| dinou dev[:esbuild|:rollup|:webpack] | In-memory VFS (Node.js) | Starts the dev server with HMR, live route typegen, and hot .env / alias / config reload (defaults to Esbuild). | Docs |
| dinou build[:node[:bundler]] & dinou start | .dinou/dist{1,2,3} (Node.js) | Compiles AOT Dual-Bundle server artifacts, SSG/PPR pages, and hashed public assets; starts production HTTP server. | Docs |
| dinou build:{netlify|cloudflare|bun|deno} | Edge / Serverless / Binaries | Multi-runtime production builds (supports :esbuild, :rollup, :webpack, :pure Bun, and :compile[:linux|:linux_arm|:mac|:win]). | Docs |
| dinou export-static[:bundler] | out/ (Static CDN) | Exports self-contained static HTML, segmented RSC payloads, and assets for CDN/GitHub Pages hosting with SPA navigation. | Docs |
| dinou typegen | .dinou/types & .dinou/routes | Regenerates routes.d.ts and contextual "./dinou" modules from src/ (ideal for CI typechecks before tsc --noEmit). | Docs |
| dinou eject / dinou uneject [version] | ./dinou/ ↔ node_modules | Copies full framework source into ./dinou (--force, --skip-install) or reverts transactionally back to npm (-y, --keep-dinou). | Docs |
Vendorized (Default) vs. Unvendorized (-u)
| Command / Env Var | Active Mode | Resolution Target | When to Use | Guide |
|---|---|---|---|---|
| npm run dev / npm run build | Vendorized (Default) | dinou/compiled/ | Daily development and production builds with instant cold starts and zero upstream dependency drift. | Docs |
| npm run dev -- -u | Unvendorized (-u / --unvendorized) | node_modules/ | Debugging upstream packages, testing local patches, or running upgraded dependencies directly from node_modules (works on Node.js and Bun). | Docs |
| DINOU_UNVENDORIZED=true | Unvendorized (Env) | node_modules/ | CI/CD pipelines or Docker containers where environment variables are preferred over CLI flags. | Docs |
| npm run build:vendors | Vendor Compiler (Ejected Only) | ./dinou/compiled/ | Recompiles the 31 standalone ESM vendor bundles in ~5s after bumping dependencies in an ejected project. | Docs |
7. Decision Matrix: When to Use WhatArchitectural Guide
Quick comparative decision tables to help you pick the right primitive for caching, navigation, and state access without trial and error.
Cache Invalidation: Which method should you call?
| Method | Caller Environment | Scope of Impact | When to Choose It |
|---|---|---|---|
| revalidatePage(path) | Server (Action / Webhook / API) | Single route page only (page.rsc + index.html) | Default for single-page edits: when updating content on a known URL (e.g. "/blog/post-1") without touching shared layouts. |
| revalidateLayout(path) | Server (Action / Webhook / API) | Single layout shell in O(1) (layout.rsc) | Shared layout updates: when updating a sidebar, header, or navigation menu (e.g. "/docs" or "/"); child routes lazily re-compose their HTML on demand. |
| revalidatePath(path) | Server (Action / Webhook / API) | Segment layout + index page at path | When a mutation updates both a section's layout and its index landing page simultaneously (e.g. "/store"). |
| revalidateTag(tag) | Server (Action / Webhook / API) | Multi-page, layout & slot cluster | Recommended for shared data models: when updating a database record (e.g., product or article) that appears across lists, detail pages, and <DinouCacheSlot> widgets. |
| refreshSlot(slotId, { fresh? }) | Client Component (Browser) | Single targeted slot (or "*") on current page | Zero layout/page re-render: when an interactive client widget updates (e.g. cart badge counter or mini ticker) without touching the rest of the page; pass { fresh: true } to bypass slot cache. |
| router.refresh({ layout? }) | Client Component (Browser) | Active page (or page + layout with { layout: true }) | When a client action needs fresh server props for the route without losing client state or scrolling to top. |
Redirection: Which redirection strategy should you use?
| Strategy | Context / Location | HTTP / Browser Mechanism | When to Choose It |
|---|---|---|---|
| Response.redirect() in onRequest | Server Plugin (dinou.config.ts) | HTTP 3xx on SSR; auto-translated to x-rsc-redirect on SPA | Global edge/auth gates: Runs ahead of cached SSG/ISR/PPR pages before any route module executes. |
| redirect(path) in getProps | Server (page_functions / layout_functions) | Real HTTP 302 Response (or x-rsc-redirect on SPA) | Fastest route-level guard: Auth checks or missing-record redirects that short-circuit rendering before JSX execution begins. |
| return redirect(path) in Component | Universal (Server or Client) | HTTP 302 / x-rsc-redirect if headers unsent; <ClientRedirect> SPA replace if stream started or on client | When redirection criteria depend on intermediate component tree logic (always return its value). |
| <ClientRedirect to="..." /> | Client Component (JSX render) | Client-side replace navigation on mount | Declarative fallback rendering in client tabs, wizard step redirections, or empty states. |
| router.replace(url) | Client Event Handler | History replace without entry | Post-submission redirect where clicking browser "Back" should not re-submit the action (e.g. login form, payment checkout). |
Route Parameter Access: Where should you read route data?
| Access Pattern | Environment | Return Type | When to Choose It |
|---|---|---|---|
| params in page.tsx (PageProps) | Universal (Server or Client) | RouteParams<Pattern> | Directly rendering route tokens in the page view (e.g. <h1>Product #{params.id}</h1>) with compile-time type validation. |
| params in layout.tsx (LayoutProps) | Universal (Server or Client) | LayoutParams<Pattern> | Shared navigation headers, dynamic breadcrumbs, or sidebars wrapping child segments (also auto-injects sibling @slot props). |
| params in @slot/page.tsx (SlotProps) | Universal (Server or Client) | SlotParams<Pattern> | Parallel slots consuming cumulative ancestor dynamic params alongside the main page. |
| params in getProps(params) | Server Only (page_functions / layout_functions) | RouteParams<Pattern> / LayoutParams<Pattern> | Fetching database records or querying external APIs based on dynamic route IDs before rendering. |
| params in not_found.tsx (NotFoundProps) | Universal (Server or Client) | RouteParams<Pattern> | Scoped 404 views displaying the missing item ID (e.g. Item "{params.slug}" not found). |
| params in error.tsx (ErrorProps) | Universal (Server or Client) | ErrorParams<Pattern> | Scoped 500 error pages (and @slot/error.tsx) showing diagnostic context or retry options for that resource. |
| usePathname() | Universal (Server or Client) | string | Navigation bars, sidebars, or layout components that need to detect the current URL path without relying on child props. |
| useSearchParams() | Universal (Server or Client) | URLSearchParams | Reading query string parameters (filters, pagination, search). Prefer Client Components on static/ISR/PPR pages to avoid dynamic SSR bailout. |
PageProps, LayoutProps, SlotProps, NotFoundProps, ErrorProps, PageFunctions, LayoutFunctions, Link, and useRouter from "./dinou" inside any route directory to skip explicit <Pattern> generics and from props completely.