React Router Params
Question
How do you access URL parameters in React Router?
Hint
useParams returns an object with route parameters.
Explanation
In React Router, URL parameters (defined with :param in routes like /users/:id) are accessed with the useParams() hook. It returns an object: { id: "123" } for /users/123. useParams must be called inside a component rendered by a Route. Route parameters are useful for detail pages, edit forms, and any route with dynamic segments. Combine with useEffect to fetch data when the param changes.
Related Resources
Related Lessons
- React Router
Learn routing.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.