Breadcrumb Navigation Implementation with Claude Code
Learn about breadcrumb navigation implementation using Claude Code. Practical tips and code examples included.
Breadcrumbs Improve UX and SEO Simultaneously
Breadcrumbs are a navigation element that visually indicate where users are within your site. Implementing them correctly improves both usability and SEO at the same time.
A Basic Breadcrumb Component
> Create a breadcrumb component.
> Include structured data (JSON-LD), accessibility, and responsive behavior.
// components/Breadcrumb.tsx
interface BreadcrumbItem {
label: string;
href?: string;
}
interface BreadcrumbProps {
items: BreadcrumbItem[];
}
export function Breadcrumb({ items }: BreadcrumbProps) {
const jsonLd = {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: items.map((item, index) => ({
'@type': 'ListItem',
position: index + 1,
name: item.label,
item: item.href ? `https://example.com${item.href}` : undefined,
})),
};
return (
<>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
<nav aria-label="Breadcrumb" className="breadcrumb">
<ol className="flex flex-wrap items-center gap-1 text-sm text-gray-600">
{items.map((item, index) => (
<li key={index} className="flex items-center">
{index > 0 && (
<span className="mx-2 text-gray-400" aria-hidden="true">/</span>
)}
{item.href && index < items.length - 1 ? (
<a
href={item.href}
className="text-blue-600 hover:underline"
>
{item.label}
</a>
) : (
<span aria-current="page" className="text-gray-800 font-medium">
{item.label}
</span>
)}
</li>
))}
</ol>
</nav>
</>
);
}
Automatically Generating Breadcrumbs From the URL
// utils/breadcrumb.ts
const labelMap: Record<string, string> = {
blog: 'Blog',
category: 'Category',
tags: 'Tags',
about: 'About',
};
export function generateBreadcrumbs(pathname: string): BreadcrumbItem[] {
const segments = pathname.split('/').filter(Boolean);
const items: BreadcrumbItem[] = [
{ label: 'Home', href: '/' },
];
let currentPath = '';
segments.forEach((segment, index) => {
currentPath += `/${segment}`;
const isLast = index === segments.length - 1;
items.push({
label: labelMap[segment] || decodeURIComponent(segment),
href: isLast ? undefined : currentPath,
});
});
return items;
}
Integration Example in Astro
---
// layouts/BlogPost.astro
import { Breadcrumb } from '../components/Breadcrumb';
const { frontmatter } = Astro.props;
const breadcrumbItems = [
{ label: 'Home', href: '/' },
{ label: 'Blog', href: '/blog' },
{ label: frontmatter.category, href: `/blog/category/${frontmatter.category}` },
{ label: frontmatter.title },
];
---
<Breadcrumb items={breadcrumbItems} />
Styling Variations
/* Arrow style */
.breadcrumb-arrow li + li::before {
content: '›';
margin: 0 0.5rem;
color: #9ca3af;
}
/* Icon style */
.breadcrumb-icon li:first-child a::before {
content: '';
display: inline-block;
width: 16px;
height: 16px;
background: url('/icons/home.svg') no-repeat center;
margin-right: 4px;
vertical-align: middle;
}
/* Mobile: show only the last two items */
@media (max-width: 640px) {
.breadcrumb li:not(:nth-last-child(-n+2)) {
display: none;
}
.breadcrumb li:nth-last-child(2)::before {
content: '... / ';
}
}
Tests
import { describe, it, expect } from 'vitest';
import { generateBreadcrumbs } from './breadcrumb';
describe('generateBreadcrumbs', () => {
it('home page', () => {
const result = generateBreadcrumbs('/');
expect(result).toEqual([{ label: 'Home', href: '/' }]);
});
it('blog article page', () => {
const result = generateBreadcrumbs('/blog/my-article');
expect(result).toHaveLength(3);
expect(result[1]).toEqual({ label: 'Blog', href: '/blog' });
expect(result[2].href).toBeUndefined();
});
});
Summary
Breadcrumbs are an important component on both the SEO and accessibility fronts. If you ask Claude Code to include structured data support in the implementation, your breadcrumbs will start showing up in Google search results. For the details on structured data, see Google Search Central.
Free PDF: Claude Code Cheatsheet in 5 Minutes
Just enter your email and we'll send you the single-page A4 cheatsheet right away.
We handle your data with care and never send spam.
Level up your Claude Code workflow
50 battle-tested prompt templates you can copy-paste into Claude Code right now.
About the Author
Masa
Engineer obsessed with Claude Code. Runs claudecode-lab.com, a 10-language tech media with 2,000+ pages.
Related Posts
7 CLAUDE.md Templates for Claude Code You Can Copy Into Real Projects
Copy-paste 7 practical CLAUDE.md templates for solo apps, content sites, APIs, teams, and legacy codebases, plus the failure cases to avoid.
Claude Code Approval and Sandbox Guide | Safe Daily Settings for Real Work
Learn how to split Claude Code actions into allow, ask, deny, and sandboxed workflows with working settings, hooks, and rollout examples.
Complete Beginner's Guide to Claude Code 2026 | 7 Steps from Zero to Production-Ready
A complete beginner's guide for first-time Claude Code users. From installation to integrating it into your real development workflow — covering every pitfall Masa ran into when starting out.
Related Products
50 Battle-Tested Claude Code Prompt Templates
Copy, paste, ship. 50 production-ready prompts.
Use proven prompts for code review, refactoring, testing, documentation, debugging, architecture, and incident response.
The Complete Claude Code Setup & Configuration Guide
From install to team-ready workflow.
A practical guide to installation, CLAUDE.md, hooks, MCP servers, permissions, IDE setup, and CI/CD workflows.