The Breadcrumbs component provides hierarchical navigation showing the user’s current location and allowing quick navigation to parent pages.
Basic usage
<flx-breadcrumbs [items]="breadcrumbItems"></flx-breadcrumbs>
Properties
Array of breadcrumb items to display
Character or icon used to separate items
Maximum number of items to show before collapsing
size
'small' | 'medium' | 'large'
default:"medium"
Size of the breadcrumb items
BreadcrumbItem interface
interface BreadcrumbItem {
label: string;
url?: string;
icon?: string;
active?: boolean;
}
Events
itemClick
EventEmitter<BreadcrumbItem>
Emitted when a breadcrumb item is clicked
Examples
Basic breadcrumbs
With icons
Custom separator
With max items
Dynamic breadcrumbs
With route data
<flx-breadcrumbs [items]="breadcrumbs"></flx-breadcrumbs>
export class ProductPage {
breadcrumbs = [
{ label: 'Home', url: '/' },
{ label: 'Products', url: '/products' },
{ label: 'Electronics', url: '/products/electronics' },
{ label: 'Laptop', active: true }
];
}
<flx-breadcrumbs [items]="breadcrumbsWithIcons"></flx-breadcrumbs>
export class DashboardPage {
breadcrumbsWithIcons = [
{ label: 'Home', url: '/', icon: 'home' },
{ label: 'Settings', url: '/settings', icon: 'settings' },
{ label: 'Profile', active: true, icon: 'user' }
];
}
<flx-breadcrumbs
[items]="breadcrumbs"
separator=">">
</flx-breadcrumbs>
<flx-breadcrumbs
[items]="breadcrumbs"
separator="→">
</flx-breadcrumbs>
<flx-breadcrumbs
[items]="longBreadcrumbs"
[maxItems]="4">
</flx-breadcrumbs>
export class DeepPage {
longBreadcrumbs = [
{ label: 'Home', url: '/' },
{ label: 'Level 1', url: '/level1' },
{ label: 'Level 2', url: '/level1/level2' },
{ label: 'Level 3', url: '/level1/level2/level3' },
{ label: 'Level 4', url: '/level1/level2/level3/level4' },
{ label: 'Current Page', active: true }
];
}
When maxItems is set, middle items are collapsed into an ellipsis (…).
<flx-breadcrumbs
[items]="breadcrumbs"
(itemClick)="onBreadcrumbClick($event)">
</flx-breadcrumbs>
import { ActivatedRoute, Router } from '@angular/router';
export class DynamicBreadcrumbs implements OnInit {
breadcrumbs: BreadcrumbItem[] = [];
constructor(
private route: ActivatedRoute,
private router: Router
) {}
ngOnInit() {
this.buildBreadcrumbs();
}
buildBreadcrumbs() {
const urlSegments = this.router.url.split('/').filter(segment => segment);
this.breadcrumbs = [
{ label: 'Home', url: '/', icon: 'home' }
];
let currentUrl = '';
urlSegments.forEach((segment, index) => {
currentUrl += `/${segment}`;
this.breadcrumbs.push({
label: this.formatLabel(segment),
url: currentUrl,
active: index === urlSegments.length - 1
});
});
}
formatLabel(segment: string): string {
return segment.replace(/-/g, ' ')
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
}
onBreadcrumbClick(item: BreadcrumbItem) {
if (item.url) {
this.router.navigate([item.url]);
}
}
}
// In your routing module
const routes: Routes = [
{
path: '',
component: HomeComponent,
data: { breadcrumb: 'Home' }
},
{
path: 'products',
component: ProductsComponent,
data: { breadcrumb: 'Products' },
children: [
{
path: ':id',
component: ProductDetailComponent,
data: { breadcrumb: 'Product Details' }
}
]
}
];
// In your breadcrumb service
@Injectable({ providedIn: 'root' })
export class BreadcrumbService {
breadcrumbs$ = this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
map(() => this.buildBreadcrumbs(this.route.root))
);
constructor(
private router: Router,
private route: ActivatedRoute
) {}
private buildBreadcrumbs(
route: ActivatedRoute,
url = '',
breadcrumbs: BreadcrumbItem[] = []
): BreadcrumbItem[] {
const children = route.children;
if (children.length === 0) {
return breadcrumbs;
}
for (const child of children) {
const routeURL = child.snapshot.url.map(segment => segment.path).join('/');
if (routeURL) {
url += `/${routeURL}`;
}
const label = child.snapshot.data['breadcrumb'];
if (label) {
breadcrumbs.push({ label, url });
}
return this.buildBreadcrumbs(child, url, breadcrumbs);
}
return breadcrumbs;
}
}
Styling
flx-breadcrumbs {
--flx-breadcrumb-font-size: 14px;
--flx-breadcrumb-text-color: #6b7280;
--flx-breadcrumb-link-color: #3b82f6;
--flx-breadcrumb-link-hover-color: #2563eb;
--flx-breadcrumb-active-color: #111827;
--flx-breadcrumb-separator-color: #9ca3af;
--flx-breadcrumb-icon-size: 16px;
--flx-breadcrumb-spacing: 8px;
}
Accessibility
The Breadcrumbs component ensures full accessibility:
<nav> element with aria-label="breadcrumb"
<ol> for proper semantic structure
- Current page marked with
aria-current="page"
- Keyboard navigation support
- Screen reader friendly
Best practices
- Always include “Home” or root level as the first item
- Mark the current page as
active: true and omit the url
- Use consistent labeling across your application
- Keep breadcrumb labels concise
- Use
maxItems for deep hierarchies to prevent overflow
- Ensure breadcrumbs reflect the actual site structure
- Update breadcrumbs dynamically as users navigate
For applications with deep navigation hierarchies, set maxItems to 4-5 to keep the breadcrumb trail manageable.
- Stepper - For sequential process navigation
- Tab Bar - For peer-level navigation