|
1 | 1 | import React, { useEffect, useState } from 'react'; |
2 | 2 | import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom'; |
| 3 | +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
3 | 4 |
|
4 | 5 | import Home from '@pages/Home'; |
5 | 6 | import Login from '@pages/Login'; |
@@ -32,6 +33,8 @@ import { getUserInfoApi } from '@apis/user'; |
32 | 33 | import { getCurrentUserId } from '@utils/getCurrentUserId'; |
33 | 34 | import Loading from '@components/Loading'; |
34 | 35 |
|
| 36 | +const queryClient = new QueryClient(); |
| 37 | + |
35 | 38 | const ProtectedRoute = ({ children }: { children: JSX.Element }) => { |
36 | 39 | const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null); |
37 | 40 |
|
@@ -98,22 +101,24 @@ const publicRoutes = [ |
98 | 101 |
|
99 | 102 | const App: React.FC = () => { |
100 | 103 | return ( |
101 | | - <BrowserRouter> |
102 | | - <Routes> |
103 | | - {/* 인증이 필요한 페이지 */} |
104 | | - {protectedRoutes.map(({ path, element }) => ( |
105 | | - <Route key={path} path={path} element={<ProtectedRoute>{element}</ProtectedRoute>} /> |
106 | | - ))} |
107 | | - |
108 | | - {/* 인증이 필요 없는 페이지 */} |
109 | | - {publicRoutes.map(({ path, element }) => ( |
110 | | - <Route key={path} path={path} element={element} /> |
111 | | - ))} |
112 | | - |
113 | | - {/* 없는 페이지에 대한 처리 */} |
114 | | - <Route path="*" element={<NotFound />} /> |
115 | | - </Routes> |
116 | | - </BrowserRouter> |
| 104 | + <QueryClientProvider client={queryClient}> |
| 105 | + <BrowserRouter> |
| 106 | + <Routes> |
| 107 | + {/* 인증이 필요한 페이지 */} |
| 108 | + {protectedRoutes.map(({ path, element }) => ( |
| 109 | + <Route key={path} path={path} element={<ProtectedRoute>{element}</ProtectedRoute>} /> |
| 110 | + ))} |
| 111 | + |
| 112 | + {/* 인증이 필요 없는 페이지 */} |
| 113 | + {publicRoutes.map(({ path, element }) => ( |
| 114 | + <Route key={path} path={path} element={element} /> |
| 115 | + ))} |
| 116 | + |
| 117 | + {/* 없는 페이지에 대한 처리 */} |
| 118 | + <Route path="*" element={<NotFound />} /> |
| 119 | + </Routes> |
| 120 | + </BrowserRouter> |
| 121 | + </QueryClientProvider> |
117 | 122 | ); |
118 | 123 | }; |
119 | 124 |
|
|
0 commit comments