From the course: Advanced React Router Techniques with TypeScript

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Dynamic routes with useParams

Dynamic routes with useParams

- [Instructor] Continuing from our exploration of nested routes, let's take things up a notch by diving into one of React Router's most powerful features, dynamic routes with useParams. While nested routes help organize your app's structure, dynamic routes make it adaptable and scalable, especially when working with unique data. Let's build on the spicy category from our menu example. Imagine creating a dynamic recipe, we are clicking on a specific spicy recipe, takes users to a detailed page for that dish. A static route setup would quickly become cumbersome, because you would need to define a route for every single recipe manually. This is where dynamic routing shines. Dynamic routes allow you to create templates for routes. These templates adapt based on unique inputs, like IDs, names or slugs. For example, in our spicy recipes section, users might click on recipes, like /menu/spicy/spicy-jollof, or /menu/spicy/chicken-pepper-soup. As you can see, the last segment of the URL is…

Contents