How does the routing system work?
How does the routing system work?
About vercel/next.js · 2 messages · last activity 7/3/2026
Based on the available repository data, I can provide information about how routing works in Next.js, though the detailed architectural implementation isn't fully visible in the retrieved sources. Here's what I can share:
Router Behavior & Request Handling
The router intercepts and manages different types of requests. According to [.agents/skills/router-act/SKILL.md:L63-L87], the router internally:
- Intercepts all router requests — prefetches, navigations, and Server Actions
- Uses a Playwright route handler to intercept requests
- Buffers responses until the scope function returns (preventing deadlocks from trying to navigate and render within the same synchronous scope)
- Waits for completion using
requestIdleCallbackto capture IntersectionObserver-triggered prefetches - Repeats until no more requests arrive
This means navigation must be triggered separately from waiting for content—you click a link within act() but read the destination page content after act returns [.agents/skills/router-act/SKILL.md:L63-L87].
Route File Structure
Next.js uses a file-system-based router with support for:
- Dynamic routes: segments wrapped in
[brackets]for parameters (e.g.,/store/[region]/[category]/[productId]) - Hierarchical routing: nested layouts that compose route segments
- Route matching: pattern-based via regex for efficient segment matching
The router also supports implicit route-based tags for caching, where revalidatePath() automatically invalidates cached data based on route hierarchy without explicit tags [.claude-plugin/plugins/cache-components/skills/cache-components/REFERENCE.md:L287-L321].
For deeper architectural details about route resolution algorithms or the core routing engine, I'd need to search the main source files, but the data available focuses on observable behavior and testing patterns.
FOLLOW_UPS:
- How does Partial Prerendering use routing?
- What are dynamic routes and how to use params?
- How does prefetching work in Next.js?
Want to ask your own question?
Open chat for vercel/next.jsPublic Q&A. Generated by RepoPilot from the actual source of vercel/next.js. AI answers can be incomplete or stale — verify before relying on them.