refactor(Sidebar.tsx): use current path to determine current page
This commit is contained in:
parent
5cb95a96fa
commit
abc85211f4
1 changed files with 4 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
import { Fragment, useState } from 'react';
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import {
|
||||
|
|
@ -28,6 +29,7 @@ function classNames(...classes: any) {
|
|||
|
||||
export function Sidebar() {
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false)
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
@ -86,7 +88,7 @@ export function Sidebar() {
|
|||
<Link
|
||||
href={item.href}
|
||||
className={classNames(
|
||||
item.current
|
||||
router.pathname === item.href
|
||||
? 'bg-gray-800 text-white'
|
||||
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
||||
'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
|
||||
|
|
@ -124,7 +126,7 @@ export function Sidebar() {
|
|||
<Link
|
||||
href={item.href}
|
||||
className={classNames(
|
||||
item.current
|
||||
router.pathname === item.href
|
||||
? 'bg-gray-800 text-white'
|
||||
: 'text-gray-400 hover:text-white hover:bg-gray-800',
|
||||
'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
|
||||
|
|
|
|||
Reference in a new issue