Q13: How do Optional Catch-all routes [[...slug]].js work?

Optional catch-all routes using double brackets [[...slug]].js match dynamic nested segments AND the base route without parameters (/docs, /docs/a, /docs/a/b). On the base path /docs, slug is undefined.

Key Takeaways
  • Matches target base paths alongside nested sub-routes.
  • Prevents creating a separate index.js file for root paths.
Knowledge Check

What is router.query.slug for pages/shop/[[...slug]].js when navigating to /shop?