Installation
Choose your runtime, then connect Cookbook Router to your build.
Three steps, then one check:
- Choose the runtime your application uses.
- Add one generation path: a bundler plugin or the CLI.
- Run
cbr initto create the config, scripts, output directory, and initial contracts. - Register the bundler plugin when applicable, then verify that TypeScript includes the generated contracts.
Choose your runtime
For React applications
Install the core router and its React integration.
pnpm add @cookbook/router @cookbook/router-reactnpm install @cookbook/router @cookbook/router-reactyarn add @cookbook/router @cookbook/router-reactbun add @cookbook/router @cookbook/router-reactUse this setup for React providers, links, hooks, outlets, slots, intercepts, blockers, and static rendering.
Other frameworks and runtimes
Install the core router.
pnpm add @cookbook/routernpm install @cookbook/routeryarn add @cookbook/routerbun add @cookbook/routerThe core router is framework-agnostic and works independently of React or any other UI library.
Add generation to your build
Generation turns static route definitions into typed route IDs, params, search, hash, autocomplete, declarations, manifests, and build-time validation.
Install the CLI and exactly one plugin for the bundler your application uses.
No supported bundler plugin
Use the CLI directly when the application uses another build system or needs generation outside the bundler lifecycle.
pnpm add -D @cookbook/router-cli
pnpm exec cbr generate --watchnpm install --save-dev @cookbook/router-cli
npx cbr generate --watchyarn add --dev @cookbook/router-cli
yarn cbr generate --watchbun add --dev @cookbook/router-cli
bunx cbr generate --watchInitialize Cookbook Router
Run the initializer once after installing the runtime and generation packages:
pnpm exec cbr initnpx cbr inityarn cbr initbunx cbr initThe initializer prepares the project for both CLI and bundler-plugin generation. It creates the router config, detects the source directory, adds route scripts, connects the generated output to TypeScript, and runs the first generation.
By default, it creates:
cookbook-router.config.ts
src/root.route.tsx
.cookbook-router/Projects using an app directory get app/root.route.tsx instead. Custom route globs do not receive an automatic starter route.
cbr init refuses to overwrite an existing router config. Existing projects should configure generation manually instead of forcing initialization over working setup.
Verify the TypeScript connection
Generated contracts do nothing if TypeScript cannot see them. Whether the CLI or a bundler plugin creates the files, inference, autocomplete, and validation only work after those files become part of the application's TypeScript program.
cbr init updates tsconfig.json automatically when it finds one. Check the configuration manually when initialization was skipped, the bundler plugin was configured by hand, or generation uses a custom outDir.
Register the generated files to TypeScript's include option:
{
"include": [
"src",
".cookbook-router/contracts.ts",
".cookbook-router/register.d.ts"
]
}Replace src when your source lives elsewhere. If you configured a different outDir, replace .cookbook-router with that path.
contracts.ts contains the route-specific types. register.d.ts connects these types to @cookbook/router and @cookbook/router-react, making route IDs, params, search, hash, metadata, and related specs available to links, navigation, hooks, and router APIs.
Do not add these files to compilerOptions.types. They must be included as source files in the TypeScript program.
No inclusion, no inference.
What gets installed
| Need | Install |
|---|---|
| Framework-agnostic routing | @cookbook/router |
| React rendering and hooks | @cookbook/router-react |
| Contract generation and validation | @cookbook/router-cli |
| Build integration | One @cookbook/router-*-plugin package |
Requirements
| Package | Runtime requirement |
|---|---|
| All packages | Node.js 18 or newer |
@cookbook/router-react | React and React DOM 18 or newer |
| Vite plugin | Vite 5 or newer |
| Webpack plugin | Webpack 5 or newer |
| Rspack plugin | Rspack 1 or newer |
| Rollup plugin | Rollup 4 or newer |
| esbuild plugin | esbuild 0.20 or newer |
| Bun plugin | Current Bun plugin API and bun-types 1 or newer for TypeScript |
Where this bites
Pick one bundler plugin. Your build only needs one, not all six.
Do not run a bundler plugin and cbr generate --watch against the same output directory. Both processes will generate the same artifacts, duplicate work, and make failures harder to diagnose.
The runtime packages make routing work. Generation is what turns the route tree into enforceable TypeScript contracts and build-time validation.