-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBreadCrumb.tsx
43 lines (36 loc) · 1.04 KB
/
BreadCrumb.tsx
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
'use client';
import { List, Space } from '@prisma/client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
type Props = {
space: Space;
list?: List;
};
export default function BreadCrumb({ space, list }: Props) {
const path = usePathname();
const parts = path.split('/').filter((p) => p);
const [base] = parts;
if (base !== 'space') {
return <></>;
}
const items: Array<{ text: string; link: string }> = [];
items.push({ text: 'Home', link: '/' });
items.push({ text: space.name || '', link: `/space/${space.slug}` });
if (list) {
items.push({
text: list?.title || '',
link: `/space/${space.slug}/${list.id}`,
});
}
return (
<div className="text-sm text-gray-600 breadcrumbs">
<ul>
{items.map((item, i) => (
<li key={i}>
<Link href={item.link}>{item.text}</Link>
</li>
))}
</ul>
</div>
);
}