Q42: What is the route specificity matching priority in the Pages Router?
When URL paths match multiple route patterns, Next.js evaluates route priority in strict order:
- Predefined explicit routes (
pages/post/create.js) - Dynamic routes (
pages/post/[id].js) - Catch-all routes (
pages/post/[...slug].js) - Optional Catch-all routes (
pages/post/[[...slug]].js)
Key Takeaways
- Explicit static route files take precedence over dynamic wildcard files.
- Optional catch-all files have the lowest specificity priority.
Knowledge Check
Which page file handles the incoming URL /posts/new if both pages/posts/new.js and pages/posts/[id].js exist?