0
0
NextJSframework~5 mins

Catch-all routes with [...param] in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a catch-all route in Next.js?
A catch-all route in Next.js is a special file-based route that matches any number of URL segments. It uses the syntax [...param] in the filename to capture all parts of the path into an array.
Click to reveal answer
beginner
How do you define a catch-all route file in Next.js?
You create a file inside the pages or app directory with the name [...param].js or [...param]/page.js. The square brackets with three dots tell Next.js to capture all matching URL parts into an array called 'param'.
Click to reveal answer
intermediate
How does Next.js pass the catch-all route parameters to the component?
Next.js passes the catch-all parameters as an array inside the params object. For example, if the route is [...slug], then params.slug will be an array of all URL segments matched.
Click to reveal answer
intermediate
What is the difference between a catch-all route [...param] and an optional catch-all route [[...param]]?
A catch-all route [...param] requires at least one URL segment to match. An optional catch-all route [[...param]] can match zero or more segments, so it also matches the base path without extra segments.
Click to reveal answer
beginner
Why use catch-all routes in Next.js?
Catch-all routes let you handle dynamic nested paths easily, like blog posts with multiple categories or user-generated URLs. They simplify routing by capturing many paths with one file.
Click to reveal answer
In Next.js, what does the file name [...slug].js represent?
AAn optional route that matches zero or one segment
BA static page with the name 'slug'
CA route that matches exactly one URL segment named 'slug'
DA catch-all route that captures multiple URL segments into an array
What type of data does Next.js provide for catch-all route parameters?
AAn array of strings representing each URL segment
BA boolean indicating if the route matched
CA string representing the full path
DAn object with keys for each segment
Which file name allows matching zero or more URL segments in Next.js routing?
A[param].js
B[[...param]].js
C[...param].js
Dparam.js
If you want to capture a URL like /blog/2024/june/post-title with one route file, which Next.js route file would you use?
Ablog/[...slug].js
Bblog/[post].js
Cblog/[[...slug]].js
Dblog/index.js
What happens if you visit the base path of a catch-all route defined as [...param].js without extra segments?
AThe route matches and param is an empty array
BThe route matches and param is undefined
CThe route does not match and returns 404
DThe route matches and param is a string
Explain how catch-all routes work in Next.js and how you access the captured parameters.
Think about how Next.js uses file names to match URLs and how it sends data to components.
You got /4 concepts.
    Describe a real-life example where catch-all routes in Next.js would be useful and why.
    Imagine a website with many levels of content categories or user pages.
    You got /4 concepts.