Lesson
Parametrize Route Loader for Nested Route in Tanstack Router
Parametrize nested route loaders in TanStack Router using path parameters
- Access
- Included
- Transcript
- Needs source
In this lesson, we learn how to parametrize the loader for a nested route in TanStack Router.
We focus on a nested route like /employees/$employeeId, where the $employeeId is a dynamic parameter.
To fetch data for this route, we use a loader function that accesses the $employeeId parameter. This is achieved by using the params object available in the loader function, which contains the dynamic segments of the URL. We then use this parameter to call a function like getEmployeeById, which fetches specific employee details from an API.
We highlights that TanStack Router automatically infers types for these parameters, ensuring type safety for nested routes.