Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat: route path 상수화
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonjeunghoon committed Aug 15, 2023
1 parent 45f17a8 commit cfd9735
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
16 changes: 16 additions & 0 deletions frontend/src/constants/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const PATH = {
app: '',
introducePage: '',
oauthPage: 'oauth/login/*',
kakao: 'kakao',
space: 'space',
writingPage: 'writings/:categoryId/:writingId',
writingTablePage: 'writings/:categoryId',
} as const;

export const NAVIGATE_PATH = {
homePage: `/${PATH.space}`,
getWritingTablePage: (categoryId: number) => `/${PATH.space}/writings/${categoryId}`,
getWritingPage: (categoryId: number, writingId: number) =>
`/${PATH.space}/writings/${categoryId}/${writingId}`,
} as const;
12 changes: 7 additions & 5 deletions frontend/src/hooks/usePageNavigate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { NAVIGATE_PATH } from 'constants/path';
import { useNavigate } from 'react-router-dom';

export const usePageNavigate = () => {
const navigate = useNavigate();

const goHomePage = () => navigate('/space');
const goHomePage = () => navigate(NAVIGATE_PATH.homePage);

const goWritingPage = ({ categoryId, writingId }: { categoryId: number; writingId: number }) =>
navigate(`/space/writings/${categoryId}/${writingId}`);
const goWritingTablePage = (categoryId: number) =>
navigate(NAVIGATE_PATH.getWritingTablePage(categoryId));

const goWritingTablePage = (categoryId: number) => navigate(`/space/writings/${categoryId}`);
const goWritingPage = ({ categoryId, writingId }: { categoryId: number; writingId: number }) =>
navigate(NAVIGATE_PATH.getWritingPage(categoryId, writingId));

return { goHomePage, goWritingPage, goWritingTablePage };
return { goHomePage, goWritingTablePage, goWritingPage };
};
15 changes: 8 additions & 7 deletions frontend/src/routes/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,37 @@ import App from '../App';
import OauthPage from 'pages/OauthPage/OauthPage';
import IntroducePage from 'pages/IntroducePage/IntroducePage';
import Layout from 'pages/Layout/Layout';
import { PATH } from 'constants/path';

export const Router = () => {
const browserRouter = createBrowserRouter([
{
path: '',
path: PATH.app,
element: <App />,
children: [
{
path: '',
path: PATH.introducePage,
element: <IntroducePage />,
},
{
path: 'oauth/login/*',
path: PATH.oauthPage,
children: [
{
path: 'kakao',
path: PATH.kakao,
element: <OauthPage />,
},
],
},
{
path: 'space',
path: PATH.space,
element: <Layout />,
children: [
{
path: 'writings/:categoryId/:writingId',
path: PATH.writingPage,
element: <WritingPage />,
},
{
path: 'writings/:categoryId',
path: PATH.writingTablePage,
element: <WritingTablePage />,
},
],
Expand Down

0 comments on commit cfd9735

Please sign in to comment.