I am working on useHistory() hook. I need to fill the breadcrumbs from the useHistory route. I need to fill the breadcrumbs from where we came to home page or '/'.I don't know how to do it using useHistory.I know only few methods like goBack(). But it gives only the previous route. I need the whole history stack. Is there any way to get that in react?
For creating a breadcrumb, you could be making use of history's location object
Something like this:
function DashboardDetail() {
const history = useHistory();
const { pathname } = history.location;
return (
<div>
<p>BreadCrumb: {pathname.split("/").join(" -> ")}</p>
<h2>Dashboard Detail</h2>
</div>
);
}
Working Example: