Skip to content

Commit

Permalink
fix: url 제대로 인식하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ocahs9 committed Jan 14, 2025
1 parent f3af725 commit 4d9dccf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
16 changes: 13 additions & 3 deletions src/common/component/Nav/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import * as styles from "./Nav.css";
import { NAV_CONTENT } from "./constant";

const Nav = () => {
const [activeItem, setActiveItem] = useState<string>("home");
const location = useLocation();

const extractFirstPath = (): string => {
const pathName = location.pathname;
const parts = pathName.split("/");
const basePath = `/${parts[1]}`;

return basePath;
};

const [activeItem, setActiveItem] = useState<string>(extractFirstPath());
const navigate = useNavigate();

const handleClick = (itemId: string, path: string) => {
setActiveItem(itemId);
if (itemId !== "review") {
if (itemId !== "/review") {
navigate(path);
} else {
alert("추후 구현 예정입니다.");
Expand Down
8 changes: 4 additions & 4 deletions src/common/component/Nav/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type NavItem = {
};

export const NAV_CONTENT: NavItem[] = [
{ id: "home", label: "홈", path: "/main", svg: IcShape },
{ id: "community", label: "커뮤니티", path: "/community", svg: IcShape },
{ id: "review", label: "병원리뷰", path: "/community", svg: IcShape },
{ id: "my", label: "마이", path: "/mypage", svg: IcShape },
{ id: "/main", label: "홈", path: "/main", svg: IcShape },
{ id: "/community", label: "커뮤니티", path: "/community", svg: IcShape },
{ id: "/review", label: "병원리뷰", path: "/community", svg: IcShape },
{ id: "/mypage", label: "마이", path: "/mypage", svg: IcShape },
];
4 changes: 3 additions & 1 deletion src/page/main/index/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Nav from "@common/component/Nav/Nav";

const Main = () => {
return <div>메인</div>;
return <Nav />;
};

export default Main;
9 changes: 4 additions & 5 deletions src/page/mypage/index/Mypage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Nav from "@common/component/Nav/Nav";

const Mypage = () => {
return (
<div>Mypage</div>
)
}
return <Nav />;
};

export default Mypage
export default Mypage;

0 comments on commit 4d9dccf

Please sign in to comment.