Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please added feature disabledLink to allow to disable link if not needed #41

Closed
phatify opened this issue Jan 28, 2022 · 6 comments
Closed
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@phatify
Copy link

phatify commented Jan 28, 2022

Please update this feature, this will be useful in some cases
, I mentioned an example for usage below:

const configs = [
  { path: '/', breadcrumb: 'Home' },
  { path: '/product', breadcrumb: 'Product', disabledLink: true },
  { path: '/product/add', breadcrumb: 'New Product' },
]
  const breadcrumbs = useBreadcrumbs(configs, { 
    disableDefaults: true 
  });

  return (
    <>
      { breadcrumbs.map((data, i) => {
        const { match, breadcrumb } = data;
        return (
          <BreadcrumbComponent key={match.pathname}>
            {match.disabledLink ?
              <>{breadcrumb}</>
               :
              <Link to={match.pathname}>{breadcrumb}</Link>          
            } 
          </BreadcrumbComponent>                   
        )
      })}
    </>
  )
@icd2k3
Copy link
Owner

icd2k3 commented Jan 28, 2022

@phatify - all additional pass-through props (props that aren't part of the react-router or use-react-router-breadcrumbs APIs) are included at the root level of the map.

So your code should look something like this instead:

EDIT (disabledLink needs to be nested in a props object within config - I forgot to include this. in the original response)

const breadcrumbs = useBreadcrumbs([
    { path: "/", breadcrumb: "Home" },
    { path: "/product", breadcrumb: "Product", props: { disabledLink: true } },
    { path: "/product/add", breadcrumb: "New Product" }
  ]);
return (
    <>
      { breadcrumbs.map((data, i) => {
        const { match, breadcrumb, disabledLink } = data;
        return (
          <BreadcrumbComponent key={match.pathname}>
            {disabledLink ?
              <>{breadcrumb}</>
               :
              <Link to={match.pathname}>{breadcrumb}</Link>          
            } 
          </BreadcrumbComponent>                   
        )
      })}
    </>
  )

@phatify
Copy link
Author

phatify commented Jan 30, 2022

@phatify - all additional pass-through props (props that aren't part of the react-router or use-react-router-breadcrumbs APIs) are included at the root level of the map.

So your code should look something like this instead:

return (
    <>
      { breadcrumbs.map((data, i) => {
        const { match, breadcrumb, disabledLink } = data;
        return (
          <BreadcrumbComponent key={match.pathname}>
            {disabledLink ?
              <>{breadcrumb}</>
               :
              <Link to={match.pathname}>{breadcrumb}</Link>          
            } 
          </BreadcrumbComponent>                   
        )
      })}
    </>
  )

@icd2k3 Have you tried yet? It not works, bro! I got the undefined from console.log(disabledLink)

@icd2k3
Copy link
Owner

icd2k3 commented Jan 30, 2022

@phatify I forgot to post the route config as well - pass through props have to be placed in a props object. I have edited my original response to reflect this as well.

const breadcrumbs = useBreadcrumbs([
    { path: "/", breadcrumb: "Home" },
    { path: "/product", breadcrumb: "Product", props: { disabledLink: true } },
    { path: "/product/add", breadcrumb: "New Product" }
  ]);

Here's a codesandbox example of the functionality you're looking for I think https://codesandbox.io/s/use-react-router-breadcrumbs-demo-forked-vxhvn?file=/Breadcrumbs.js

@icd2k3
Copy link
Owner

icd2k3 commented Jan 30, 2022

This props option is also noted in the api section of the readme but might be worth having it's own section if we see more questions like this

@phatify
Copy link
Author

phatify commented Jan 30, 2022

@icd2k3 Thanks for your answer. Its saved my time. :)))

@icd2k3 icd2k3 added question Further information is requested documentation Improvements or additions to documentation labels Jan 30, 2022
@icd2k3
Copy link
Owner

icd2k3 commented Jan 30, 2022

No problem @phatify and sorry for the confusion - I've adjusted the "advanced" example in the readme slightly to highlight the props object. Closing this issue because it sounds like it solved your issue.

@icd2k3 icd2k3 closed this as completed Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants