Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Add Routing to Breadcrumb component

I've created a Breadcrumb component but I'm struggling to add routing to it.

So far, the component is able to load a custom number of nodes based on how many elements we send to an array and it logs into the console the name of the node when clicked.

What it is needed is to make this breadcrumb change the url when a node is clicked.

It should contain something like this:

  <Switch>
    <Route path="/component0" component={Component0} />
    <Route path="/component1" component={Component1} />
    ...
  </Switch>

Is it possible to make it for a custom number of nodes?

This is the code so far:

Parent component:

import React, { useState } from 'react';

import Breadcrumbs from './Breadcrumbs';
export interface BreadcrumbProps {}

export function Breadcrumb(props: BreadcrumbProps) {
  const [crumbs, setCrumbs] = useState(['Home', 'Category', 'Sub Category']);

  const selected = (crumb: any) => {
    console.log(crumb);
  };

  return (
    <div>
      <Breadcrumbs crumbs={crumbs} selected={selected} />
    </div>
  );
}

export default Breadcrumb;

Child component:

function Breadcrumbs(props: any) {
  function isLast(index: number) {
    return index === props.crumbs.length - 1;
  }

  return (
    <nav className=''>
      <ol className=''>
        {props.crumbs.map((crumb, ci) => {
          const disabled = isLast(ci) ? 'disabled' : '';

          return (
            <li key={ci} className=''>
              <button className={`btn btn-link ${disabled}`} onClick={() => props.selected(crumb)}>
                {crumb}
              </button>
            </li>
          );
        })}
      </ol>
    </nav>
  );
}

export default Breadcrumbs;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!