From 938c783e0f6f3297e3badc29e26c86639406144c Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Wed, 27 Dec 2023 14:28:32 +0100 Subject: [PATCH] Chapter 5 - Highlight navigation --- app/ui/dashboard/nav-links.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/ui/dashboard/nav-links.tsx b/app/ui/dashboard/nav-links.tsx index 8a8212b..90b325b 100644 --- a/app/ui/dashboard/nav-links.tsx +++ b/app/ui/dashboard/nav-links.tsx @@ -1,3 +1,4 @@ +'use client' import { UserGroupIcon, HomeIcon, @@ -5,6 +6,8 @@ import { } from '@heroicons/react/24/outline'; import Link from 'next/link'; +import { usePathname } from 'next/navigation'; +import clsx from 'clsx'; // Map of links to display in the side navigation. // Depending on the size of the application, this would be stored in a database. @@ -19,6 +22,7 @@ const links = [ ]; export default function NavLinks() { + const pathname = usePathname(); return ( <> {links.map((link) => { @@ -27,8 +31,12 @@ export default function NavLinks() { + className={clsx( + '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', + { + 'bg-sky-100 text-blue-600': pathname === link.href, + }, + )} >

{link.name}