typescriptbeginner
Dynamic Breadcrumb Component
Generates breadcrumb navigation automatically from the current URL path segments.
typescriptPress ⌘/Ctrl + Shift + C to copy
interface BreadcrumbProps {
items: { label: string; href?: string }[];
separator?: string;
}
export function Breadcrumb({ items, separator = '/' }: BreadcrumbProps) {
return (
<nav aria-label="Breadcrumb" className="text-sm text-gray-400">
<ol className="flex items-center gap-2">
{items.map((item, i) => (
<li key={i} className="flex items-center gap-2">
{i > 0 && <span className="text-gray-600">{separator}</span>}
{item.href && i < items.length - 1 ? (
<a href={item.href} className="hover:text-white transition-colors">
{item.label}
</a>
) : (
<span className="text-white">{item.label}</span>
)}
</li>
))}
</ol>
</nav>
);
}
export function pathToBreadcrumbs(path: string): { label: string; href: string }[] {
const segments = path.split('/').filter(Boolean);
return segments.map((segment, i) => ({
label: segment.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()),
href: '/' + segments.slice(0, i + 1).join('/'),
}));
}Use Cases
- Site navigation
- SEO structured data
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptintermediate
Error Boundary with Fallback UI
Class-based error boundary component that catches render errors and displays a customizable fallback UI.
Best for: Graceful error recovery
#error-boundary#error-handling
typescriptintermediate
Portal-Based Modal Component
Accessible modal component using React portals with focus trapping, Escape key close, and backdrop click.
Best for: Confirmation dialogs
#modal#portal
typescriptbeginner
useDocumentTitle Hook
Dynamically updates the document title and restores it on unmount.
Best for: Page title updates
#hooks#document
typescriptintermediate
useStepWizard Hook
Multi-step wizard hook that manages step navigation, validation gates, and completion state.
Best for: Onboarding flows
#hooks#wizard