0
0
NextJSframework~5 mins

Dynamic routes with [param] in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a dynamic route in Next.js?
A dynamic route in Next.js is a page route that uses square brackets [param] in the filename to capture variable parts of the URL, allowing the page to render different content based on the URL segment.
Click to reveal answer
beginner
How do you define a dynamic route for a user profile page with a user ID in Next.js?
You create a file named [userId].js inside the pages or app directory. The [userId] part captures the user ID from the URL, like /profile/123, where 123 is the userId.
Click to reveal answer
intermediate
How do you access the dynamic parameter inside a Next.js page component?
You use the useRouter hook from 'next/router' or the params object in server components to get the dynamic parameter value from the URL.
Click to reveal answer
beginner
What is the difference between a static route and a dynamic route in Next.js?
A static route has a fixed path like /about, while a dynamic route uses [param] to match many paths like /product/1, /product/2, where the param changes.
Click to reveal answer
intermediate
Can you have multiple dynamic segments in a Next.js route? How?
Yes, you can have multiple dynamic segments by naming files like [category]/[id].js. This captures two parameters from the URL, for example /books/123.
Click to reveal answer
What does the file name [postId].js represent in Next.js routing?
AA dynamic route capturing postId from the URL
BA static route named postId
CA component that cannot be routed
DA special API route
How do you get the value of a dynamic route parameter inside a client component?
AUsing window.location.pathname
BUsing getStaticProps only
CUsing useRouter hook from 'next/router'
DUsing CSS selectors
Which URL matches the dynamic route file [category]/[id].js?
A/category
B/books/123
C/123/books
D/books
What happens if you visit a dynamic route URL that does not match any file?
ANext.js shows a 404 page
BNext.js redirects to home
CNext.js crashes
DNext.js shows a blank page
Can dynamic routes be nested inside folders in Next.js?
AOnly static routes can be nested
BNo, all dynamic routes must be in root
CDynamic routes must be flat files
DYes, you can nest dynamic routes in folders
Explain how to create and use a dynamic route with [param] in Next.js.
Think about how the file name relates to the URL and how to get the value inside the component.
You got /4 concepts.
    Describe the difference between static and dynamic routes in Next.js and when to use each.
    Consider how URLs look and what content changes.
    You got /4 concepts.