Breadcrumb.tsx 908 B

12345678910111213141516171819202122232425262728293031
  1. import { ChevronRight } from 'lucide-react';
  2. import { useLocation } from 'react-router-dom';
  3. import { findTrail } from './nav-utils';
  4. /** 内容区顶部面包屑:L1 / L2 / L3,末项高亮(docs/01 §2.3)。 */
  5. export function Breadcrumb() {
  6. const { pathname } = useLocation();
  7. const trail = findTrail(pathname);
  8. if (!trail.length) return null;
  9. return (
  10. <nav
  11. aria-label="breadcrumb"
  12. className="flex items-center gap-1 text-xs text-muted-foreground"
  13. >
  14. {trail.map((n, i) => {
  15. const last = i === trail.length - 1;
  16. return (
  17. <span key={n.key} className="flex items-center gap-1">
  18. {i > 0 && <ChevronRight className="size-3 opacity-60" />}
  19. <span className={last ? 'text-foreground font-medium' : ''}>
  20. {n.label}
  21. </span>
  22. </span>
  23. );
  24. })}
  25. </nav>
  26. );
  27. }
  28. export default Breadcrumb;