-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBreadcrumb.jsx
38 lines (33 loc) · 862 Bytes
/
Breadcrumb.jsx
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
// import { useState } from 'react'
import { useRouter } from 'next/router'
import { toCapitalize } from '../utils/string'
export default function Breadcrumb() {
const router = useRouter()
const routes = ['Home', ...router.asPath.split('/').slice(1)].filter(
(v) => v !== ''
)
return (
<nav className="pb-3" aria-label="Breadcrumb">
{routes.map((route, i) => {
let weight
switch (i) {
case 0:
weight = 'bold'
break
case 1:
weight = 'semibold'
break
default:
weight = 'normal'
break
}
return (
<span key={i} className={`font-${weight}`}>
{toCapitalize(route, '-', ' ')}{' '}
{i !== routes.length - 1 ? '> ' : ''}
</span>
)
})}
</nav>
)
}