From 71e319f81d302f3e176e78aff89be439e1094992 Mon Sep 17 00:00:00 2001 From: pcshen0828 Date: Sun, 9 Jul 2023 00:29:48 +0800 Subject: [PATCH] fix: sidebar links --- components/shared/Sidebar.tsx | 54 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/components/shared/Sidebar.tsx b/components/shared/Sidebar.tsx index 4fa38b8f..5cbe9171 100644 --- a/components/shared/Sidebar.tsx +++ b/components/shared/Sidebar.tsx @@ -1,43 +1,51 @@ -import { useState } from "react"; +import Link from "next/link"; +import { useRouter } from "next/router"; + import Button from "./Button"; import HomeIcon from "./Icon/group/home"; import NewsIcon from "./Icon/group/news"; import RoomsIcon from "./Icon/group/rooms"; + import { cn } from "@/lib/utils"; -enum SidebarActive { - NEWS = "news", - HOME = "home", - ROOMS = "rooms", +enum SidebarRoutes { + HOME = "/", + ROOMS = "/rooms", + NEWS = "/news", } export default function Sidebar() { - const [selected, setSelected] = useState(SidebarActive.NEWS); + const router = useRouter(); + const { pathname } = router; const buttons = [ - { text: "公告", Icon: NewsIcon, type: SidebarActive.NEWS }, - { text: "遊戲大廳", Icon: HomeIcon, type: SidebarActive.HOME }, - { text: "遊戲房間", Icon: RoomsIcon, type: SidebarActive.ROOMS }, + { text: "公告", Icon: NewsIcon, route: SidebarRoutes.NEWS }, + { text: "遊戲大廳", Icon: HomeIcon, route: SidebarRoutes.HOME }, + { text: "遊戲房間", Icon: RoomsIcon, route: SidebarRoutes.ROOMS }, ]; return ( );