-
Notifications
You must be signed in to change notification settings - Fork 887
Expand file tree
/
Copy pathNavigationLink.tsx
More file actions
59 lines (54 loc) · 1.62 KB
/
NavigationLink.tsx
File metadata and controls
59 lines (54 loc) · 1.62 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
57
58
59
import clsx from 'clsx'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { Tag } from '@/components/Tag'
import { NavLink } from './routes'
export function NavigationLink({
className,
link,
}: {
className?: string
link: NavLink
}) {
const pathname = usePathname()
// Add this to get the hash
const hash = typeof window !== 'undefined' ? window.location.hash : ''
// Modify the isActive check to include hash comparison if needed
const isActive = pathname === link.href ||
(link.href.includes('#') && pathname + hash === link.href)
// const pathname = usePathname()
// console.log(link)
// console.log(link.title, pathname, link.href)
// const isActive = pathname === link.href
return (
<Link
href={link.href}
aria-current={isActive ? 'page' : undefined}
className={clsx(
'flex justify-between mb-[2px] py-1 px-2 text-sm transition rounded-md hover:bg-zinc-800 transition-colors',
isActive
? 'text-white bg-zinc-800'
: 'hover:text-white text-zinc-400 bg-transparent',
className,
)}
>
<div className="flex items-center justify-start gap-1">
{link.icon}
{link.tag ? (
<div className="flex items-center gap-2">
<span className={clsx('truncate', isActive ? 'text-white' : '')}>
{link.title}
</span>
<Tag>
{link.tag}
</Tag>
</div>
) : (
<span className={clsx('truncate', isActive ? 'text-white' : '')}>
{link.title}
</span>
)}
</div>
</Link>
)
}