Skip to content

Commit d15fbd1

Browse files
committed
feat: lazy loading to pages
1 parent 510c568 commit d15fbd1

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

Frontend/src/pages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import EditJob from './EditJob';
1111
import NotFoundPage from './NotFoundPage';
1212
import ForgotPassword from './ForgotPassword';
1313
import ResetPassword from './ResetPassword';
14-
import VerifyEmail from './verifyEmail';
14+
import VerifyEmail from './VerifyEmail';
1515
import PrivacyPolicy from './PrivacyPolicy';
1616
import Terms from './Terms';
1717
export { Home, Login, Signup, Dashboard, CreateJob, Jobs, EditJob, Logs, VerifyEmail, ForgotPassword, ResetPassword, NotFoundPage, JobLogs, Settings, PrivacyPolicy, Terms }

Frontend/src/routes.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
1+
import { lazy, Suspense } from "react";
12
import { createBrowserRouter } from "react-router-dom";
2-
import { Home, Login, Signup, Dashboard, CreateJob, Jobs, ResetPassword, EditJob, Logs, JobLogs, Settings, NotFoundPage, ForgotPassword, VerifyEmail, PrivacyPolicy, Terms } from "./pages";
3-
import { Layout, ProtectedRoute, PublicRoute } from "./components";
3+
import { Home, Login, Signup, Dashboard, CreateJob, Jobs, EditJob, Logs, JobLogs, Settings, NotFoundPage, ForgotPassword } from "./pages";
4+
import { Layout, ProtectedRoute, PublicRoute, Loader } from "./components";
5+
6+
const PrivacyPolicy = lazy(() => import("./pages/PrivacyPolicy"));
7+
const Terms = lazy(() => import("./pages/Terms"));
8+
const VerifyEmail = lazy(() => import("./pages/VerifyEmail"));
9+
const ResetPassword = lazy(() => import("./pages/ResetPassword"));
410

511
export const router = createBrowserRouter([
612
{ path: "/", element: <Home /> },
7-
{ path: "/privacy-policy", element: <PrivacyPolicy /> },
8-
{ path: "/terms", element: <Terms /> },
913

14+
{
15+
path: "/privacy-policy",
16+
element: (
17+
<Suspense fallback={<Loader />}>
18+
<PrivacyPolicy />
19+
</Suspense>
20+
),
21+
},
22+
{
23+
path: "/terms",
24+
element: (
25+
<Suspense fallback={<Loader />}>
26+
<Terms />
27+
</Suspense>
28+
),
29+
},
1030
{ path: "/login", element: <PublicRoute><Login /></PublicRoute> },
1131
{ path: "/signup", element: <PublicRoute><Signup /></PublicRoute> },
1232
{ path: "/forgot-password", element: <PublicRoute><ForgotPassword /></PublicRoute> },
1333

14-
{ path: "/verify-email/:userId", element: <VerifyEmail /> },
15-
{ path: "/reset-password/:token", element: <ResetPassword /> },
34+
{
35+
path: "/verify-email/:userId",
36+
element: (
37+
<Suspense fallback={<Loader />}>
38+
<VerifyEmail />
39+
</Suspense>
40+
),
41+
},
42+
{
43+
path: "/reset-password/:token",
44+
element: (
45+
<Suspense fallback={<Loader />}>
46+
<ResetPassword />
47+
</Suspense>
48+
),
49+
},
1650

1751
{
1852
element: <ProtectedRoute />,
@@ -27,10 +61,10 @@ export const router = createBrowserRouter([
2761
{ path: "/job/:jobId/edit", element: <EditJob /> },
2862
{ path: "/logs", element: <Logs /> },
2963
{ path: "/settings", element: <Settings /> },
30-
]
31-
}
32-
]
64+
],
65+
},
66+
],
3367
},
3468

35-
{ path: "*", element: <NotFoundPage /> }
69+
{ path: "*", element: <NotFoundPage /> },
3670
]);

0 commit comments

Comments
 (0)