|
| 1 | +--- |
| 2 | +title: useOverrideBreadcrumb |
| 3 | +description: Hook for dynamically overriding breadcrumb titles from within page components |
| 4 | +--- |
| 5 | + |
| 6 | +# useOverrideBreadcrumb |
| 7 | + |
| 8 | +React hook to dynamically override the breadcrumb title for the current page. Useful for displaying data-driven titles (e.g., record names fetched from an API) instead of static route-based titles. |
| 9 | + |
| 10 | +## Signature |
| 11 | + |
| 12 | +```typescript |
| 13 | +function useOverrideBreadcrumb(title: string | undefined): void; |
| 14 | +``` |
| 15 | + |
| 16 | +## Parameters |
| 17 | + |
| 18 | +### `title` |
| 19 | + |
| 20 | +- **Type:** `string | undefined` |
| 21 | +- **Required:** Yes |
| 22 | +- **Description:** The title to display in the breadcrumb for the current path. When `undefined`, any previous override is removed and the default title (from `defineResource`) is restored. |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### With `defineResource` |
| 27 | + |
| 28 | +```tsx |
| 29 | +import { useOverrideBreadcrumb } from "@tailor-platform/app-shell"; |
| 30 | + |
| 31 | +defineResource({ |
| 32 | + path: ":id", |
| 33 | + component: () => { |
| 34 | + const { id } = useParams(); |
| 35 | + const { data } = useQuery(GET_ORDER, { variables: { id } }); |
| 36 | + |
| 37 | + // Update breadcrumb with the order name |
| 38 | + useOverrideBreadcrumb(data?.order?.name); |
| 39 | + |
| 40 | + return <OrderDetail />; |
| 41 | + }, |
| 42 | +}); |
| 43 | +``` |
| 44 | + |
| 45 | +### With file-based routing |
| 46 | + |
| 47 | +```tsx |
| 48 | +import { useOverrideBreadcrumb, useParams } from "@tailor-platform/app-shell"; |
| 49 | + |
| 50 | +const OrderDetailPage = () => { |
| 51 | + const { id } = useParams(); |
| 52 | + const { data } = useQuery(GET_ORDER, { variables: { id } }); |
| 53 | + |
| 54 | + // Update breadcrumb with the order name |
| 55 | + useOverrideBreadcrumb(data?.order?.name); |
| 56 | + |
| 57 | + return <div>...</div>; |
| 58 | +}; |
| 59 | + |
| 60 | +export default OrderDetailPage; |
| 61 | +``` |
| 62 | + |
| 63 | +## Notes |
| 64 | + |
| 65 | +- The hook updates reactively — pass the result of a data-fetching query directly and the breadcrumb updates when the data resolves. |
| 66 | +- When `title` is `undefined` (e.g., while data is loading), the override is cleared and the default title is shown. |
| 67 | +- The override is automatically cleaned up when the component unmounts. |
| 68 | + |
| 69 | +## Related |
| 70 | + |
| 71 | +- [defineResource](define-resource) - Define routes and their default breadcrumb titles |
| 72 | +- [Routing and Navigation](../concepts/routing-navigation) - Overview of breadcrumb behavior |
0 commit comments