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:

  1. Predefined explicit routes (pages/post/create.js)
  2. Dynamic routes (pages/post/[id].js)
  3. Catch-all routes (pages/post/[...slug].js)
  4. 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?