Skip to content

Commit d8581fb

Browse files
authored
➕ react router 설치 및 navigation 로직 생성 (#9)
* ➕ react router 설치 * ✨ 랜딩페이지, 로그인 페이지, 회원가입 페이지 생성 * ✨ router provider 생성 * ♻️ path 상수화 * 👔 navigation을 위한 서비스 로직 생성 및 각 페이지에 적용
1 parent a62f2db commit d8581fb

10 files changed

Lines changed: 115 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@tailwindcss/vite": "^4.3.0",
1717
"react": "^19.1.0",
1818
"react-dom": "^19.1.0",
19+
"react-router": "^7.16.0",
1920
"tailwindcss": "^4.3.0"
2021
},
2122
"devDependencies": {

pnpm-lock.yaml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import { useState } from 'react';
1+
import { RouterProvider } from './routes/router-provider';
22

33
export const App = () => {
4-
const [count, setCount] = useState(0);
5-
6-
return (
7-
<div>
8-
<p>Hello World!</p>
9-
<button onClick={() => setCount((count) => count + 1)}>
10-
Count is {count}
11-
</button>
12-
</div>
13-
);
4+
return <RouterProvider />;
145
};

src/main.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { StrictMode } from 'react';
22
import { createRoot } from 'react-dom/client';
3+
import { BrowserRouter } from 'react-router';
34
import { App } from './App';
45

56
const rootElement = document.getElementById('root');
@@ -9,6 +10,8 @@ if (rootElement === null) {
910

1011
createRoot(rootElement).render(
1112
<StrictMode>
12-
<App />
13+
<BrowserRouter>
14+
<App />
15+
</BrowserRouter>
1316
</StrictMode>
1417
);

src/pages/landing.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useRouteNavigation } from '../routes/use-route-navigation';
2+
3+
export const LandingPage = () => {
4+
const { toSignIn, toSignUp } = useRouteNavigation();
5+
6+
return (
7+
<div>
8+
<p>랜딩 페이지입니다.</p>
9+
<button onClick={toSignIn}>로그인</button>
10+
<button onClick={toSignUp}>회원가입</button>
11+
</div>
12+
);
13+
};

src/pages/sign-in.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useRouteNavigation } from '../routes/use-route-navigation';
2+
3+
export const SignInPage = () => {
4+
const { toMain } = useRouteNavigation();
5+
6+
return (
7+
<div>
8+
<p>로그인 페이지입니다.</p>
9+
<button onClick={toMain}>메인으로</button>
10+
</div>
11+
);
12+
};

src/pages/sign-up.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useRouteNavigation } from '../routes/use-route-navigation';
2+
3+
export const SignUpPage = () => {
4+
const { toMain } = useRouteNavigation();
5+
6+
return (
7+
<div>
8+
<p>회원가입 페이지입니다.</p>
9+
<button onClick={toMain}>메인으로</button>
10+
</div>
11+
);
12+
};

src/routes/path.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const PATH = {
2+
LANDING: '/',
3+
SIGN_IN: '/sign-in',
4+
SIGN_UP: '/sign-up',
5+
};

src/routes/router-provider.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Route, Routes } from 'react-router';
2+
import { LandingPage } from '../pages/landing';
3+
import { SignInPage } from '../pages/sign-in';
4+
import { SignUpPage } from '../pages/sign-up';
5+
import { PATH } from './path';
6+
7+
export const RouterProvider = () => {
8+
return (
9+
<Routes>
10+
<Route path={PATH.LANDING} element={<LandingPage />} />
11+
<Route path={PATH.SIGN_IN} element={<SignInPage />} />
12+
<Route path={PATH.SIGN_UP} element={<SignUpPage />} />
13+
</Routes>
14+
);
15+
};

src/routes/use-route-navigation.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useNavigate } from 'react-router';
2+
import { PATH } from './path';
3+
4+
export const useRouteNavigation = () => {
5+
const navigate = useNavigate();
6+
const { LANDING, SIGN_IN, SIGN_UP } = PATH;
7+
8+
return {
9+
toMain: () => {
10+
void navigate(LANDING);
11+
},
12+
toSignIn: () => {
13+
void navigate(SIGN_IN);
14+
},
15+
toSignUp: () => {
16+
void navigate(SIGN_UP);
17+
},
18+
toBack: () => {
19+
void navigate(-1);
20+
},
21+
refreshPage: () => {
22+
void navigate(0);
23+
},
24+
};
25+
};

0 commit comments

Comments
 (0)