Problem Statement
Explain how nested routes work in Next.js and provide an example structure.
Explanation
Nested routes in Next.js mirror the folder structure where subdirectories create nested URL paths, so pages/blog/index.js creates /blog and pages/blog/[slug].js creates /blog/any-slug for dynamic blog posts.
You can nest as deeply as needed with pages/blog/category/[category]/[post].js creating /blog/category/tech/my-post routes.
In App Router, folders define route segments and each folder can have its own layout.js that wraps child routes, creating persistent layouts that don't unmount on navigation.
For example, app/dashboard/layout.js wraps all /dashboard routes including /dashboard/settings and /dashboard/profile, allowing shared UI and state across related pages.