import { Fragment } from 'react'; import { Link } from '@@/Link'; export interface Crumb { label: string; link?: string; linkParams?: Record; } interface Props { breadcrumbs: (Crumb | string)[] | string; } export function Breadcrumbs({ breadcrumbs }: Props) { const breadcrumbsArray = Array.isArray(breadcrumbs) ? breadcrumbs : [breadcrumbs]; return (
{breadcrumbsArray.map((crumb, index) => ( {renderCrumb(crumb)} {index !== breadcrumbsArray.length - 1 && >} ))}
); } function renderCrumb(crumb: Crumb | string) { if (!crumb) { return ''; } if (typeof crumb === 'string') { return crumb; } if (crumb.link) { return ( {crumb.label} ); } return crumb.label; }