Using handle
DRANK

You can build dynamic UI elements like breadcrumbs based on your route hierarchy using the useMatches hook and handle route exports.Understanding the BasicsReact Router provides access to all route matches and their data throughout your component tree. This allows routes to contribute metadata through the handle export that can be rendered by ancestor components.The useMatches hook combined with handle exports enables routes to contribute to rendering processes higher up the component tree than their actual render point. While we'll use breadcrumbs as an example, this pattern works for any scenario where you need routes to provide additional information to their ancestors.Defining Route handlesWe'll use a route structure like the following:import { route } from "@react-router/dev/routes"; export default [ route("parent", "./routes/parent.tsx", [ route("child", "./routes/child.tsx"), ]), ] satisfies RouteConfig; Add a breadcrumb property to the "parent" route's handle export. Y…

reactrouter.com
Related Topics: