Skip to content

Commit

Permalink
✨ feat: nav bar 조건부 랜더링 #39
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeona01 committed Oct 24, 2024
1 parent 8e3827d commit 059748c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 35 deletions.
36 changes: 19 additions & 17 deletions src/components/Common/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Navbar = () => {
svg: SearchIcon,
},
{
path: '/documents',
path: '/applicants',
svg: DocumentsIcon,
},
{
Expand All @@ -32,22 +32,24 @@ const Navbar = () => {
];

return (
<section className="w-full py-6 px-12 bg-navbarGradient rounded-[2rem]">
<div className="flex justify-between items-center">
{routes.map((route, index) => {
const IconComponent = route.svg;
return (
<button key={index} onClick={() => navigate(route.path)}>
{route.path == '/profile' ? (
<IconComponent stroke={getIconColor(route.path)} />
) : (
<IconComponent fill={getIconColor(route.path)} />
)}
</button>
);
})}
</div>
</section>
<div className="flex justify-center items-center z-50">
<section className="fixed bottom-4 w-[90%] py-6 px-8 bg-navbarGradient rounded-[2rem]">
<div className="flex justify-between items-center">
{routes.map((route, index) => {
const IconComponent = route.svg;
return (
<button key={index} onClick={() => navigate(route.path)}>
{route.path == '/profile' ? (
<IconComponent stroke={getIconColor(route.path)} />
) : (
<IconComponent fill={getIconColor(route.path)} />
)}
</button>
);
})}
</div>
</section>
</div>
);
};

Expand Down
54 changes: 36 additions & 18 deletions src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { Outlet, useLocation } from 'react-router-dom';
import HomePage from '@/pages/Home/HomePage';
import SigninPage from '@/pages/Signin/SigninPage';
import SignupPage from '@/pages/Signup/SignupPage';
import InformationPage from '@/pages/Information/InformationPage';
import ApplicationDocumentsPage from '@/pages/ApplicationDocuments/ApplicationDocumentsPage';
import WriteDocumentsPage from '@/pages/WriteDocuments/WriteDocumentsPage';
import PostSearchPage from '@/pages/PostSearch/PostSearchPage';
import PostSearchFilterPage from '@/pages/PostSearchFilter/PostSearchFilterPage';
import ProfilePage from '@/pages/Profile/ProfilePage';
Expand All @@ -13,28 +13,46 @@ import EditProfilePage from '@/pages/Profile/EditProfilePage';
import PostDetailPage from '@/pages/PostDetail/PostDetailPage';
import PostApplyPage from '@/pages/PostApply/PostApplyPage';
import ScrollToTop from '@/components/Common/ScrollToTop';
import Navbar from '@/components/Common/Navbar';

const Layout = () => {
const location = useLocation();

// Nav bar 컴포넌트가 랜딩되는 페이지
const showNavbarPaths = ['/', '/profile', '/search', '/applicants'];

const shouldShowNavbar = showNavbarPaths.includes(location.pathname);

return (
<>
<ScrollToTop />
<Outlet />
{shouldShowNavbar && <Navbar />}
</>
);
};

const Router = () => {
return (
<BrowserRouter>
<ScrollToTop />
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/information" element={<InformationPage />} />
<Route path="/signin" element={<SigninPage />} />
<Route path="/signup" element={<SignupPage />} />
<Route
path="/application-documents"
element={<ApplicationDocumentsPage />}
/>
<Route path="/write-documents" element={<WriteDocumentsPage />} />
<Route path="/search" element={<PostSearchPage />} />
<Route path="/search/filter" element={<PostSearchFilterPage />} />
<Route path="/profile" element={<ProfilePage />} />
<Route path="/profile/language" element={<LanguageSettingPage />} />
<Route path="/profile/edit" element={<EditProfilePage />} />
<Route path="/post/:id" element={<PostDetailPage />} />
<Route path="/post/apply/:id" element={<PostApplyPage />} />
<Route element={<Layout />}>
<Route path="/" element={<HomePage />} />
<Route path="/information" element={<InformationPage />} />
<Route path="/signin" element={<SigninPage />} />
<Route path="/signup" element={<SignupPage />} />
<Route
path="/application-documents"
element={<ApplicationDocumentsPage />}
/>
<Route path="/search" element={<PostSearchPage />} />
<Route path="/search/filter" element={<PostSearchFilterPage />} />
<Route path="/profile" element={<ProfilePage />} />
<Route path="/profile/language" element={<LanguageSettingPage />} />
<Route path="/profile/edit" element={<EditProfilePage />} />
<Route path="/post/:id" element={<PostDetailPage />} />
<Route path="/post/apply/:id" element={<PostApplyPage />} />
</Route>
</Routes>
</BrowserRouter>
);
Expand Down

0 comments on commit 059748c

Please sign in to comment.