--- name: typed-routes version: 1.3.1 description: | Generate typed route helpers with `pracht typegen` and replace hard-coded hrefs and `navigate()` paths with route-id links. Use for "add typed routes", "fix typed links", "replace hard-coded hrefs", "run typegen". allowed-tools: - Bash - Read - Write - Edit - Grep - Glob - AskUserQuestion --- # Pracht Typed Routes Use this workflow to keep route ids, params, links, and navigation type-safe. ## Step 1: Inspect the resolved graph The resolved app graph is the source of truth — not a manual glob of `src/`. MCP: if `pracht dev-mcp` is registered, prefer its `inspect_*`, `generate_*`, `doctor`, and `verify` tools to the CLI. ```bash pracht inspect routes --json ``` Check every route has a stable id. Explicit `id` fields are preferred for routes that app code links to, because fallback ids change when paths change. ```ts route("/products/:id", () => import("./routes/products/[id].tsx"), { id: "product", render: "ssr", }); ``` Any route without an explicit `id` — manifest apps included, not just pages-router apps — gets a fallback id derived from the route path (`/` → `index`, `/blog/:slug` → `blog-slug`, `/*` → `splat`). ## Step 2: Generate route types and helpers New `create-pracht` apps generate types after installation and before their `dev` and `typecheck` scripts. For an existing app, run: ```bash pracht typegen ``` This writes: - `src/pracht.d.ts` — module augmentation for route ids, params, loader data types, and API route request/response types (consumed by `apiFetch()`). - `src/pracht-routes.ts` — runtime `href()` helper backed by the same route map. - `src/pracht-capabilities.d.ts` — only when the app registers capabilities: input/output types from the capability schemas, so `invokeCapability()`, `callCapability()`, and `