Next.js Typed Routes in 2026: Enabling `typedRoutes` Experimentally and What It Catches That TypeScript Alone Misses A developer demonstrated how enabling Next.js's experimental `typedRoutes` flag generates type definitions from the `app/` directory structure, turning route strings into compile-time-checked values. The generated `.next/types/link.d.ts` file exports a `Route` union type that constrains `href` props on `next/link` and calls to `useRouter`, catching nonexistent routes and mistyped dynamic segments that plain TypeScript accepts. Enabling the flag requires App Router, TypeScript 5.0 or later, and a single `experimental.typedRoutes: true` entry in `next.config.ts`. typedRoutes Experimentally and What It Catches That TypeScript Alone Misses This article was written with the assistance of AI, under human supervision and review. Most route bugs in Next.js stem from string literals that TypeScript treats as valid code but that fail at runtime. A developer writes /products when the folder structure defines /product , or passes id: "123" to a route expecting a numeric segment. TypeScript compiles both without complaint. The user clicks a link and lands on a 404 page. The cost appears later, in support tickets or lost conversions, not in the editor where the mistake was made. The typedRoutes experimental flag changes this. When enabled, Next.js generates type definitions from the actual file structure in app/ and makes every route reference a type-checked operation. A route that does not exist becomes a compile-time error. A dynamic segment that receives the wrong type triggers a red squiggle before the code reaches production. This matters because the feedback loop compresses from hours or days to seconds. Developers see the mistake where they made it. The distinction between runtime discovery and compile-time prevention is the difference between shipping broken links and catching them before commit. app/ directory structure, turning route strings into type-checked values. href props all gain type safety when the flag is enabled. Enabling typedRoutes requires three conditions: a Next.js project using App Router, TypeScript 5.0 or later, and the experimental flag set in the config file. The configuration itself is a single property in next.config.ts : python import type { NextConfig } from 'next' const config: NextConfig = { experimental: { typedRoutes: true, }, } export default config When the dev server starts with this flag, Next.js scans the app/ directory and writes generated type definitions to .next/types/link.d.ts . This file contains a union type of every valid route path in the application. The TypeScript language server reads this file and enforces the types in Link components, useRouter hooks, and redirect calls. The .next/types directory is build-time output. It should be added to .gitignore alongside .next/ . When another developer clones the repository and runs npm run dev , Next.js regenerates the types for their local file structure. This regeneration happens automatically on every file system change that affects routes adding a folder, deleting a page, renaming a dynamic segment . The TypeScript version matters because the generated types rely on template literal types and recursive conditional types introduced in TypeScript 4.1 and refined in 5.0. A project stuck on TypeScript 4.9 will see type errors in the generated definitions themselves. Upgrading TypeScript is a prerequisite, not an optional step. The .next/types/link.d.ts file is a single type definition that exports a Route type. This type is a union of string literals representing every route the application defines. For a simple app structure: app/ page.tsx about/ page.tsx blog/ slug / page.tsx Next.js generates a Route type approximately like this: export type Route = "/" | "/about" | /blog/${string} Dynamic segments appear as template literal types. The slug folder becomes /blog/${string} . Optional catch-all segments ...slug generate more complex unions. The generated file is read-only. Modifying it manually does nothing because the next build overwrites the changes. The Link component from next/link uses this Route type to constrain its href prop. When developers write