0
Challenge · 12Data & Reads
Dynamic routes & async params/searchParams
Routingused in ~95% of apps
Every detail page, every filtered list, every share link runs through this: how do you read the `[id]` in the URL and the `?sort=newest` after it? In Next.js 16 the answer changed — `params` and `searchParams` are now Promises, and reading them the old (synchronous) way throws. Get this wrong and your job-detail page won't even compile.
Core idea. A folder named `[id]` makes a dynamic segment; its value arrives in the `params` prop. Query strings arrive in `searchParams`. In Next.js 16 both are Promises — you `await` them inside an async Server Component. The old synchronous access (`params.id`, `searchParams.sort`) is gone.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
app.dev/users/7
matched route: <Route path="/users/:id" element={<User />} />
visit /users/
function User() {
const { id} = useParams();
// id === "7" (always a string)
const user = db.get(id);
if (!user) return <NotFound/>;
return <Profile user={user} />;
}
rendersProfile
M
Milo Vance
Designer
Berlin
user #7
The URL segment "7" is read by useParams() as the string id, and the component looks up record #7.
↑ play a little first, then dig in