How do you create a /blog/[slug] route and access the slug value?
Source: nextjs.orgintermediate
WHAT IT TESTS: Next.js file-system routing and param access. ANSWER OUTLINE: Use a [slug] directory with page.js; in App Router read the params prop in server components or useParams in client components.
WHAT IT TESTS: Deep familiarity with Next.js dynamic routing and the critical API differences between App Router and Pages Router. ANSWER OUTLINE: Create app/blog/[slug]/page.js; in the App Router, a Server Component receives params as a direct prop, while a Client Component must import useParams from next/navigation; in the older Pages Router, access the same value through useRouter().query.
Read the original → nextjs.org
- #next.js
- #dynamic-routes
- #app-router
- #pages-router
- #intermediate
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.