Skip to content

Commit c57328a

Browse files
committed
feat: dashboard nav replaced with next's link
1 parent 8f2eed4 commit c57328a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

app/ui/dashboard/nav-links.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
1+
"use client";
2+
13
import {
24
UserGroupIcon,
35
HomeIcon,
46
DocumentDuplicateIcon,
5-
} from '@heroicons/react/24/outline';
7+
} from "@heroicons/react/24/outline";
8+
import clsx from "clsx";
9+
10+
import Link from "next/link";
11+
import { usePathname } from "next/navigation";
612

713
// Map of links to display in the side navigation.
814
// Depending on the size of the application, this would be stored in a database.
915
const links = [
10-
{ name: 'Home', href: '/dashboard', icon: HomeIcon },
16+
{ name: "Home", href: "/dashboard", icon: HomeIcon },
1117
{
12-
name: 'Invoices',
13-
href: '/dashboard/invoices',
18+
name: "Invoices",
19+
href: "/dashboard/invoices",
1420
icon: DocumentDuplicateIcon,
1521
},
16-
{ name: 'Customers', href: '/dashboard/customers', icon: UserGroupIcon },
22+
{ name: "Customers", href: "/dashboard/customers", icon: UserGroupIcon },
1723
];
1824

1925
export default function NavLinks() {
26+
const pathname = usePathname();
27+
2028
return (
2129
<>
2230
{links.map((link) => {
2331
const LinkIcon = link.icon;
2432
return (
25-
<a
33+
<Link
2634
key={link.name}
2735
href={link.href}
28-
className="flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3"
36+
className={clsx(
37+
"flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3",
38+
{ "bg-sky-100 text-blue-600": pathname === link.href }
39+
)}
2940
>
3041
<LinkIcon className="w-6" />
3142
<p className="hidden md:block">{link.name}</p>
32-
</a>
43+
</Link>
3344
);
3445
})}
3546
</>

0 commit comments

Comments
 (0)