You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add breadcrumbs to your existing [route config](https://reacttraining.com/react-router/web/example/route-config). This is a great way to keep all routing config paths in a single place! If a path ever changes, you'll only have to change it in your main route config rather than maintaining a _separate_ config for `use-react-router-breadcrumbs`.
136
+
Add breadcrumbs to your existing [route object](https://reactrouter.com/docs/en/v6/examples/route-objects). This is a great way to keep all routing config paths in a single place! If a path ever changes, you'll only have to change it in your main route config rather than maintaining a _separate_ config for `use-react-router-breadcrumbs`.
137
137
138
138
For example...
139
139
140
140
```js
141
-
constrouteConfig= [
141
+
constroutes= [
142
142
{
143
143
path:"/sandwiches",
144
-
component:Sandwiches
144
+
element:<Sandwiches/>
145
145
}
146
146
];
147
147
```
148
148
149
149
becomes...
150
150
151
151
```js
152
-
constrouteConfig= [
152
+
constroutes= [
153
153
{
154
154
path:"/sandwiches",
155
-
component:Sandwiches,
155
+
element:<Sandwiches/>,
156
156
breadcrumb:'I love sandwiches'
157
157
}
158
158
];
159
159
```
160
160
161
-
then you can just pass the whole route config right into the hook:
161
+
then you can just pass the whole routes right into the hook:
162
162
163
163
```js
164
-
constbreadcrumbs=useBreadcrumbs(routeConfig);
164
+
constbreadcrumbs=useBreadcrumbs(routes);
165
165
```
166
166
167
167
## Dynamic breadcrumb components
168
168
169
-
If you pass a component as the `breadcrumb` prop it will be injected with react-router's [match](https://reacttraining.com/react-router/web/api/match) and [location](https://reacttraining.com/react-router/web/api/location) objects as props. These objects contain ids, hashes, queries, etc... from the route that will allow you to map back to whatever you want to display in the breadcrumb.
169
+
If you pass a component as the `breadcrumb` prop it will be injected with react-router's [match](https://reactrouter.com/docs/en/v6/api#matchpath) and [location](https://reactrouter.com/docs/en/v6/api#location) objects as props. These objects contain ids, hashes, queries, etc... from the route that will allow you to map back to whatever you want to display in the breadcrumb.
170
170
171
-
Let's use `redux` as an example with the [match](https://reacttraining.com/react-router/web/api/match) object:
171
+
Let's use `redux` as an example with the [match](https://reactrouter.com/docs/en/v6/api#matchpath) object:
You cannot use hooks that rely on `RouteContext` like `useParams`, because the breadcrumbs are not in the context, you should use `match.params` instead:
const UserBreadcrumb:BreadcrumbComponentType<'id'> = ({ match }) => {
203
+
return <div>{match.params.id}</div>;
204
+
}
205
+
```
206
+
197
207
----
198
208
199
-
Similarly, the [location](https://reacttraining.com/react-router/web/api/location) object could be useful for displaying dynamic breadcrumbs based on the route's state:
209
+
Similarly, the [location](https://reactrouter.com/docs/en/v6/api#location) object could be useful for displaying dynamic breadcrumbs based on the route's state:
200
210
201
211
```jsx
202
212
// dynamically update EditorBreadcrumb based on state info
0 commit comments