nextjs-breadcrumbs icon indicating copy to clipboard operation
nextjs-breadcrumbs copied to clipboard

omitIndexList doesn't work with the 0th index

Open westdom opened this issue 3 years ago • 5 comments

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;

westdom avatar Jan 14 '22 09:01 westdom

Any way to implement this properly?

robertstojs avatar May 24 '22 11:05 robertstojs

I am having the same issue. Any updates on this?

HamaDler avatar Aug 22 '22 12:08 HamaDler

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 avatar Aug 22 '22 17:08 LAKnoKAL

@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;
     }

HamaDler avatar Aug 24 '22 08:08 HamaDler

any movement on this? 👀

mctrl avatar Mar 16 '23 17:03 mctrl