Router
Router
@dex/router is Dex's file-based React router, route/layout code generator, and client runtime (@dex/router/client). In v0.2.6 it provides concurrent route transitions, built-in error boundaries, subdomain routing, SSG prerender context, expanded page metadata, and deterministic route precedence.
Topics
- Routing Rules — File-based routing patterns, ignore rules, and precedence
- Dynamic Routes — Capturing
[param]and[...catchAll]URL segments - Layouts — Global layouts, named layouts,
<Outlet />, and page metadata - Client Navigation —
<Link />,<FileRouter />,<RouterErrorBoundary />, hooks, subdomain routing, and SSG context - Reference — Complete
@dex/routerand@dex/router/clientAPI reference
How It Works
- Generate —
generateFsRoutesandgenerateLayoutsscanweb/pages/andweb/layouts/(ignoring_-prefixed entries and symbolic links) to emitcore/router/.generated/routes.ts,manifest.json, andlayouts.ts. - Prerender & Serve —
dexPrerenderand@dex/servermatch static routes, provideRouterContextviacreateStaticRouterState, and serve prerendered HTML or SPA fallback. - Navigate —
<FileRouter />matches routes client-side, loads page and layout modules with error-evicting caches, commits updates inside ReactuseTransition, and wraps views in<RouterErrorBoundary />.
Quick Example
web/pages/
├─ index.tsx # /
├─ about.tsx # /about
├─ _helpers/format.ts # Ignored (_ prefix)
└─ users/[id].tsx # /users/:idCLI Commands
# Generate routes and layouts once
bunx --bun dex-router generate
# Watch pages and layouts during development
bunx --bun dex-router watch
# Start full dev environment (includes router watcher)
bun run dev
# Build for production (regenerates routes + SSG prerendering)
bun run buildSee Also
- File-Based Routing — Core concept
- How Dex Works — Mental model