Question presented to candidate: "You are building a product listing page in the App Router. Inside a Client Component you need the current path, the query string and the dynamic route values. Which hooks do you use, what does each return, and what goes wrong if you are careless with them?"
What a strong answer should cover:
- All three come from
next/navigationand only work in Client Components ('use client'). usePathname()returns the path string without the query;useSearchParams()returns a read-onlyURLSearchParams(get,getAll,has);useParams()returns the dynamic segments, with arrays for catch-all routes and{}when there are none.- They update on client navigation, which is why they work inside layouts where server props would go stale.
- On a prerendered route,
useSearchParamscannot know the query at build time, so the component must sit inside<Suspense>or the build fails; with Cache Components the same applies tousePathnameanduseParamsfor params not covered bygenerateStaticParams. - In a Server Component use the page
paramsandsearchParamsprops instead; to change the query, build a newURLSearchParamsand callrouter.push/replaceor render aLink.
Clarifying questions expected:
- "Is the page prerendered or rendered per request?" β it decides whether a Suspense boundary is required.
- "Should a filter change add a history entry?" β
pushversusreplace.
Code / implementation expected: Yes β a Client Component reading the three values, and updating one query parameter.