Performance: Catch-all routes with [...param]
This affects page load speed and routing performance by how Next.js matches and renders dynamic routes.
pages/[...param].js import { useMemo } from 'react'; export default function Page({ params }) { const path = useMemo(() => params.param?.join('/') ?? '', [params.param]); return <div>{path}</div>; } export async function getStaticPaths() { return { paths: [], fallback: 'blocking' }; } export async function getStaticProps({ params }) { // fetch minimal data return { props: { params } }; }
pages/[...param].js export default function Page({ params }) { // heavy logic to parse params and fetch data return <div>{params.param?.join('/')}</div>; } // No caching or static optimization
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Catch-all route without static paths | Minimal DOM nodes | 1 reflow on render | Low paint cost | [!] OK |
| Catch-all route with getStaticPaths and fallback blocking | Minimal DOM nodes | 1 reflow on render | Low paint cost | [OK] Good |
[...param] do in Next.js?[...param] matches any URL path that starts with the route prefix and captures all remaining parts./blog?[...param] to capture multiple segments./blog, the file must be named blog/[...param].js.pages/shop/[...items].js and the URL /shop/electronics/phones/smartphones, what will be the value of items inside getServerSideProps?[...items] captures all URL parts after /shop as an array./shop/electronics/phones/smartphones, the parts after /shop are electronics, phones, and smartphones.pages/docs/[...slug].js. The developer tries to access slug.join('-') but gets an error. What is the likely cause?/docs with no extra parts, the catch-all slug parameter is undefined.join on undefinedjoin on undefined causes an error because join is an array method./profile and any deeper paths like /profile/settings/privacy. Which filename should you use to make the parameter optional and avoid errors when no extra path is given?/profile and deeper paths, use optional catch-all syntax with double brackets: [[...params]].[...params] requires at least one path segment; optional catch-all [[...params]] allows zero or more segments.Pass the test and this pattern moves unknown