Skip to content

Commit d67054a

Browse files
committed
feat: 사이드 네비게이션 아이템의 활성 상태 로직 개선
1 parent abfc2df commit d67054a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/components/SideNav.astro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import {type Icon as IconType, House, Cog} from "@lucide/astro";
33
import SideNavItem from "./SideNavItem.astro";
44
5-
const {pathname} = Astro.url;
6-
75
type MenuItem = {
86
name: string;
97
pathname: string;

src/components/SideNavItem.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import {type Icon as IconType, House, Cog} from "@lucide/astro";
33
interface Props {
44
pathname: string;
55
label: string;
6-
icon: IconType; // You can specify a more precise type if needed
6+
icon: IconType;
77
}
88
99
const {pathname, label, icon} = Astro.props;
10+
11+
const active = pathname === Astro.url.pathname.replace(/\/+$/, '');
1012
---
1113

1214
<a href={pathname} class=`p-3 flex flex-row items-center gap-3 cursor-pointer rounded-full text-bright select-none transition-all
1315
hover:bg-bright hover:text-gray-950
1416
active:scale-105
15-
${pathname === Astro.url.pathname && 'bg-bright text-gray-950'}`>
17+
${active && 'bg-bright text-gray-950'}`>
1618
<slot/>
1719
<span>{label}</span>
1820
</a>

0 commit comments

Comments
 (0)