nextjs-breadcrumbs
nextjs-breadcrumbs copied to clipboard
omitIndexList doesn't work with the 0th index
With the path "/home/policy/about", I would expect omitIndexList={[0]} to either remove "/home" or "/policy". Instead it removes neither. With omitIndexList={[1]} it removes "/about".
Heres my breadcrumbs component in full:
import Breadcrumbs from 'nextjs-breadcrumbs';
import styles from './Breadcrumbs.module.css';
import { startCase } from 'lodash';
const formatLabel = (title) => {
return startCase(title.replace(/-/g, ' '));
};
const generateOmittedIndexList = (isPolicy) => {
if (isPolicy) {
return [0];
}
return [];
};
const CustomBreadcrumbs = (isPolicy) => {
return (
<Breadcrumbs
containerClassName={styles.breadcrumb}
listClassName={styles.breadcrumbItem}
activeItemClassName={styles.lastBreadcrumbItem}
transformLabel={(title) => formatLabel(title)}
omitIndexList={generateOmittedIndexList(isPolicy)}
/>
);
};
export default CustomBreadcrumbs;
Any way to implement this properly?
I am having the same issue. Any updates on this?
Not sure why it's not merged yet but the PR with fix of this issue is here for a while - https://github.com/NiklasMencke/nextjs-breadcrumbs/pull/32
@LAKnoKAL I locally patched the fix from #32 using patch-package, but that didn't seem to fix it for me. I wonder if that's the reason they still haven't accepted/merged that PR. Here's my patch file for reference.
diff --git a/node_modules/nextjs-breadcrumbs/dist/index.js b/node_modules/nextjs-breadcrumbs/dist/index.js
index a9979b3..8638dd7 100644
--- a/node_modules/nextjs-breadcrumbs/dist/index.js
+++ b/node_modules/nextjs-breadcrumbs/dist/index.js
@@ -99,9 +99,8 @@ var Breadcrumbs = function Breadcrumbs(_ref) {
}, React__default.createElement(Link, {
href: "/"
}, React__default.createElement("a", null, convertBreadcrumb(rootLabel || 'Home', labelsToUppercase, replaceCharacterList, transformLabel)))), breadcrumbs.length >= 1 && breadcrumbs.map(function (breadcrumb, i) {
- if (!breadcrumb || breadcrumb.breadcrumb.length === 0 || omitIndexList && omitIndexList.find(function (value) {
- return value === i;
- })) {
+ if (!breadcrumb || breadcrumb.breadcrumb.length === 0 || omitIndexList && omitIndexList.includes(i)
+ ) {
return;
}
any movement on this? 👀