@@ -8,6 +8,8 @@ import profileLoader from "./pages/ProfilePage/loader/profileLoader";
88
99import NoticeDetailSkeleton from "./components/NoticeDetailSkeleton" ;
1010import PageErrorElement from "./components/PageErrorElement" ;
11+ import ProtectedRoute from "./components/ProtectedRoute" ;
12+ import { loginProtectCondition } from "./constants/router" ;
1113import { ROUTES } from "./constants/router" ;
1214import AuthLayout from "./layouts/AuthLayout" ;
1315import MainLayout from "./layouts/MainLayout" ;
@@ -45,77 +47,116 @@ const NotFoundPage = lazy(() => import("@/pages/NotFoundPage"));
4547const authRoutes : RouteObject [ ] = [
4648 {
4749 path : ROUTES . AUTH . SIGNUP ,
48- Component : SignupPage ,
50+ element : < SignupPage /> ,
4951 } ,
5052 {
5153 path : ROUTES . AUTH . SIGNIN ,
52- Component : SigninPage ,
54+ element : < SigninPage /> ,
5355 } ,
5456] ;
5557
5658const shopRoutes : RouteObject [ ] = [
5759 {
5860 path : ROUTES . SHOP . ROOT ,
59- Component : ShopPage ,
61+ element : < ShopPage /> ,
6062 } ,
6163 {
6264 path : ROUTES . SHOP . REGISTER ,
63- Component : ShopRegisterPage ,
65+ element : < ShopRegisterPage /> ,
6466 handle : { hideFooter : true } ,
6567 } ,
6668 {
6769 path : ROUTES . SHOP . EDIT ,
68- Component : ShopEditPage ,
70+ element : < ShopEditPage /> ,
6971 handle : { hideFooter : true } ,
7072 } ,
7173] ;
7274
7375const profileRoutes : RouteObject [ ] = [
7476 {
7577 path : ROUTES . PROFILE . ROOT ,
76- Component : ProfilePage ,
78+ element : (
79+ < ProtectedRoute
80+ conditions = { ( { isLoggedIn, user } ) => [
81+ loginProtectCondition ( isLoggedIn ) ,
82+ {
83+ isPass : user ?. type === "employee" ,
84+ redirectPath : ROUTES . SHOP . ROOT ,
85+ message : "알바생 계정으로만 이용 가능한 기능입니다." ,
86+ } ,
87+ ] }
88+ >
89+ < ProfilePage />
90+ </ ProtectedRoute >
91+ ) ,
7792 loader : profileLoader ,
7893 } ,
7994 {
8095 path : ROUTES . PROFILE . REGISTER ,
81- Component : ProfileRegisterPage ,
96+ element : < ProfileRegisterPage /> ,
8297 handle : { hideFooter : true } ,
8398 } ,
8499 {
85100 path : ROUTES . PROFILE . EDIT ,
86- Component : ProfileEditPage ,
101+ element : < ProfileEditPage /> ,
87102 handle : { hideFooter : true } ,
88103 } ,
89104] ;
90105
91106const noticeRoutes : RouteObject [ ] = [
92107 {
93108 path : ROUTES . NOTICE . ROOT ,
94- Component : NoticeListPage ,
109+ element : < NoticeListPage /> ,
95110 } ,
96111 {
97112 path : ROUTES . NOTICE . SEARCH ,
98- Component : NoticeSearchPage ,
113+ element : < NoticeSearchPage /> ,
99114 } ,
100115 {
101116 path : ROUTES . NOTICE . REGISTER ,
102- Component : NoticeRegisterPage ,
117+ element : < NoticeRegisterPage /> ,
103118 handle : { hideFooter : true } ,
104119 } ,
105120 {
106121 path : ROUTES . NOTICE . EDIT ,
107- Component : NoticeEditPage ,
122+ element : < NoticeEditPage /> ,
108123 handle : { hideFooter : true } ,
109124 } ,
110125 {
111126 path : ROUTES . NOTICE . NOTICE_ID . EMPLOYER ,
112- Component : NoticeEmployerPage ,
127+ element : (
128+ < ProtectedRoute
129+ conditions = { ( { isLoggedIn, user } ) => [
130+ loginProtectCondition ( isLoggedIn ) ,
131+ {
132+ isPass : user ?. type === "employer" ,
133+ redirectPath : ROUTES . PROFILE . ROOT ,
134+ message : "사장님 계정으로만 이용 가능한 기능입니다." ,
135+ } ,
136+ ] }
137+ >
138+ < NoticeEmployerPage />
139+ </ ProtectedRoute >
140+ ) ,
113141 loader : noticeEmployerLoader ,
114142 hydrateFallbackElement : < NoticeDetailSkeleton /> ,
115143 } ,
116144 {
117145 path : ROUTES . NOTICE . NOTICE_ID . EMPLOYEE ,
118- Component : NoticeEmployeePage ,
146+ element : (
147+ < ProtectedRoute
148+ conditions = { ( { isLoggedIn, user } ) => [
149+ loginProtectCondition ( isLoggedIn ) ,
150+ {
151+ isPass : user ?. type === "employee" ,
152+ redirectPath : ROUTES . SHOP . ROOT ,
153+ message : "알바생 계정으로만 이용 가능한 기능입니다." ,
154+ } ,
155+ ] }
156+ >
157+ < NoticeEmployeePage />
158+ </ ProtectedRoute >
159+ ) ,
119160 loader : noticeEmployeeLoader ,
120161 hydrateFallbackElement : < NoticeDetailSkeleton /> ,
121162 } ,
@@ -125,12 +166,12 @@ const appRoutes: RouteObject[] = [
125166 ...shopRoutes ,
126167 ...profileRoutes ,
127168 ...noticeRoutes ,
128- { path : "*" , Component : NotFoundPage } ,
169+ { path : "*" , element : < NotFoundPage /> } ,
129170] ;
130171
131172export const router = createBrowserRouter ( [
132173 {
133- Component : AuthLayout ,
174+ element : < AuthLayout /> ,
134175 children : [
135176 {
136177 children : authRoutes ,
@@ -139,7 +180,7 @@ export const router = createBrowserRouter([
139180 ] ,
140181 } ,
141182 {
142- Component : MainLayout ,
183+ element : < MainLayout /> ,
143184 children : [
144185 {
145186 children : appRoutes ,
0 commit comments