Skip to content

Commit 82fdd4f

Browse files
committed
fix: 링크 active시 색상변경
1 parent f252c1e commit 82fdd4f

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/components/layout/Header.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { Link, NavLink } from "react-router-dom";
1+
import { Link, NavLink, useLocation } from "react-router-dom";
22

33
import pandaLogo from "@/assets/logo.png";
44
import UserIcon from "@/assets/ic_user.svg";
55
import { HeaderStyle } from "@/components/layout/Header.style";
66
import { WidthContainer } from "@/styles/commonStyle";
77

88
function Header() {
9+
const { pathname } = useLocation();
10+
11+
const itemsActive = pathname.startsWith("/items") || pathname === "/additem";
912
return (
1013
<HeaderStyle>
1114
<WidthContainer>
@@ -27,7 +30,9 @@ function Header() {
2730
<li>
2831
<NavLink
2932
to="/items"
30-
className={({ isActive }) => (isActive ? "active" : "")}
33+
className={({ isActive }) =>
34+
isActive || itemsActive ? "active" : ""
35+
}
3136
>
3237
중고마켓
3338
</NavLink>

src/components/layout/Header.style.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const HeaderStyle = styled.header`
6666
text-decoration: underline;
6767
text-underline-offset: 4px;
6868
text-decoration-thickness: 2px;
69+
color: var(--primary-100);
6970
}
7071
7172
.user_img {

0 commit comments

Comments
 (0)