How do I create react-router v4 breadcrumbs?

Monty picture Monty · Feb 22, 2017 · Viewed 23.2k times · Source

How do I create react-router v4 breadcrumbs? I tried asking this question on the react-router V4 website via an issue ticket. They just said to see the recursive paths example. I really want to create it in semantic-ui-react

Answer

Felipe Taboada picture Felipe Taboada · Mar 13, 2017

I was after the same thing and your question pointed me in the right direction.

This worked for me:

const Breadcrumbs = (props) => (
    <div className="breadcrumbs">
        <ul className='container'>
            <Route path='/:path' component={BreadcrumbsItem} />
        </ul>
    </div>
)

const BreadcrumbsItem = ({ match, ...rest }) => (
    <React.Fragment>
        <li className={match.isExact ? 'breadcrumb-active' : undefined}>
            <Link to={match.url || ''}>
                {match.url}
            </Link>
        </li>
        <Route path={`${match.url}/:path`} component={BreadcrumbsItem} />
    </React.Fragment>
)