-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathAutoBreadcrumbs.tsx
More file actions
56 lines (45 loc) · 1.46 KB
/
AutoBreadcrumbs.tsx
File metadata and controls
56 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use client';
import { usePathname } from 'next/navigation';
import Breadcrumbs, { BreadcrumbItem } from '@/components/Breadcrumbs';
// Map path segments to display names
const pathLabels: Record<string, string> = {
about: 'About',
recents: 'Recent Reviews',
privacy: 'Privacy Policy',
schedule: 'Schedule',
course: 'Courses',
user: 'Account',
reviews: 'My Reviews',
availability: 'Availability',
};
export default function AutoBreadcrumbs() {
const pathname = usePathname();
// Don't show breadcrumbs on home page
if (pathname === '/' || pathname === '/index') {
return null;
}
const segments = pathname.split('/').filter(Boolean);
// Don't show breadcrumbs if no meaningful segments or only "index"
if (segments.length === 0 || (segments.length === 1 && segments[0] === 'index')) {
return null;
}
const items: BreadcrumbItem[] = [];
let currentPath = '';
segments.forEach((segment, index) => {
currentPath += `/${segment}`;
const isLast = index === segments.length - 1;
// Check if this is a course ID (e.g., CS-6250)
const isCourseId = /^[A-Z]+-\d+$/.test(segment.toUpperCase());
let label: string;
if (isCourseId) {
label = segment.toUpperCase(); // Display course ID
} else {
label = pathLabels[segment] || segment.charAt(0).toUpperCase() + segment.slice(1);
}
items.push({
label,
href: isLast ? undefined : currentPath,
});
});
return <Breadcrumbs items={items} />;
}