I'm trying to write a react Breadcrumbs component which automatically sets the needed number for go back navigation in react-router-dom.
I have an array with pathnames, it's length can be 2 or more. All items are links which go back on several steps except the last one
users(goes two pages back) / name(goes on the previous page) / type(inactive)
I decided to use useNavigation hook in react-router-dom to go back.
// This is my array, for instance
const pathnames = ['users', 'name', 'type'];
So I need a function/method which will look like this.
pathTokens.map((item, index, arr) => {
if (item !== arr[arr.length - 1]) {
return <BreadcrumbsItem action ={() => navigate(numberOfStepsBack)} content={item}/>
} else {
return <BreadcrumbsItem content={item}/>
}
});