1- import React from 'react' ;
1+ import React , { Suspense } from 'react' ;
22import { HashRouter , Navigate , Route , Routes } from 'react-router-dom' ;
33import { Layout } from './components/layout/Layout' ;
44import { ThemeWrapper } from './components/layout/ThemeWrapper' ;
@@ -8,21 +8,24 @@ import { ToastProvider } from './contexts/ToastContext';
88import { ConfirmProvider } from './contexts/ConfirmContext' ;
99import { ToastContainer } from './components/ui/Toast' ;
1010import { ErrorBoundary } from './components/ErrorBoundary' ;
11- import { Auth } from './pages/Auth' ;
12- import { Dashboard } from './pages/Dashboard' ;
13- import { Friends } from './pages/Friends' ;
14- import { GroupDetails } from './pages/GroupDetails' ;
15- import { Groups } from './pages/Groups' ;
16- import { Profile } from './pages/Profile' ;
17- import { SplitwiseCallback } from './pages/SplitwiseCallback' ;
18- import { SplitwiseGroupSelection } from './pages/SplitwiseGroupSelection' ;
19- import { SplitwiseImport } from './pages/SplitwiseImport' ;
11+ import { PageLoader } from './components/ui/PageLoader' ;
12+
13+ // Lazy load pages
14+ const Auth = React . lazy ( ( ) => import ( './pages/Auth' ) . then ( module => ( { default : module . Auth } ) ) ) ;
15+ const Dashboard = React . lazy ( ( ) => import ( './pages/Dashboard' ) . then ( module => ( { default : module . Dashboard } ) ) ) ;
16+ const Friends = React . lazy ( ( ) => import ( './pages/Friends' ) . then ( module => ( { default : module . Friends } ) ) ) ;
17+ const GroupDetails = React . lazy ( ( ) => import ( './pages/GroupDetails' ) . then ( module => ( { default : module . GroupDetails } ) ) ) ;
18+ const Groups = React . lazy ( ( ) => import ( './pages/Groups' ) . then ( module => ( { default : module . Groups } ) ) ) ;
19+ const Profile = React . lazy ( ( ) => import ( './pages/Profile' ) . then ( module => ( { default : module . Profile } ) ) ) ;
20+ const SplitwiseCallback = React . lazy ( ( ) => import ( './pages/SplitwiseCallback' ) . then ( module => ( { default : module . SplitwiseCallback } ) ) ) ;
21+ const SplitwiseGroupSelection = React . lazy ( ( ) => import ( './pages/SplitwiseGroupSelection' ) . then ( module => ( { default : module . SplitwiseGroupSelection } ) ) ) ;
22+ const SplitwiseImport = React . lazy ( ( ) => import ( './pages/SplitwiseImport' ) . then ( module => ( { default : module . SplitwiseImport } ) ) ) ;
2023
2124// Protected Route Wrapper
2225const ProtectedRoute = ( { children } : { children : React . ReactElement } ) => {
2326 const { isAuthenticated, isLoading } = useAuth ( ) ;
2427
25- if ( isLoading ) return < div className = "h-screen w-full flex items-center justify-center" > Loading... </ div > ;
28+ if ( isLoading ) return < PageLoader / >;
2629
2730 if ( ! isAuthenticated ) {
2831 return < Navigate to = "/login" replace /> ;
@@ -35,21 +38,23 @@ const AppRoutes = () => {
3538 const { isAuthenticated } = useAuth ( ) ;
3639
3740 return (
38- < Routes >
39- < Route path = "/login" element = { ! isAuthenticated ? < ThemeWrapper > < Auth /> </ ThemeWrapper > : < Navigate to = "/dashboard" /> } />
40- < Route path = "/signup" element = { ! isAuthenticated ? < ThemeWrapper > < Auth /> </ ThemeWrapper > : < Navigate to = "/dashboard" /> } />
41-
42- < Route path = "/dashboard" element = { < ProtectedRoute > < Dashboard /> </ ProtectedRoute > } />
43- < Route path = "/groups" element = { < ProtectedRoute > < Groups /> </ ProtectedRoute > } />
44- < Route path = "/groups/:id" element = { < ProtectedRoute > < GroupDetails /> </ ProtectedRoute > } />
45- < Route path = "/friends" element = { < ProtectedRoute > < Friends /> </ ProtectedRoute > } />
46- < Route path = "/profile" element = { < ProtectedRoute > < Profile /> </ ProtectedRoute > } />
47- < Route path = "/import/splitwise" element = { < ProtectedRoute > < SplitwiseImport /> </ ProtectedRoute > } />
48- < Route path = "/import/splitwise/select-groups" element = { < ProtectedRoute > < SplitwiseGroupSelection /> </ ProtectedRoute > } />
49- < Route path = "/import/splitwise/callback" element = { < ProtectedRoute > < SplitwiseCallback /> </ ProtectedRoute > } />
50-
51- < Route path = "*" element = { < Navigate to = { isAuthenticated ? "/dashboard" : "/login" } /> } />
52- </ Routes >
41+ < Suspense fallback = { < PageLoader /> } >
42+ < Routes >
43+ < Route path = "/login" element = { ! isAuthenticated ? < ThemeWrapper > < Auth /> </ ThemeWrapper > : < Navigate to = "/dashboard" /> } />
44+ < Route path = "/signup" element = { ! isAuthenticated ? < ThemeWrapper > < Auth /> </ ThemeWrapper > : < Navigate to = "/dashboard" /> } />
45+
46+ < Route path = "/dashboard" element = { < ProtectedRoute > < Dashboard /> </ ProtectedRoute > } />
47+ < Route path = "/groups" element = { < ProtectedRoute > < Groups /> </ ProtectedRoute > } />
48+ < Route path = "/groups/:id" element = { < ProtectedRoute > < GroupDetails /> </ ProtectedRoute > } />
49+ < Route path = "/friends" element = { < ProtectedRoute > < Friends /> </ ProtectedRoute > } />
50+ < Route path = "/profile" element = { < ProtectedRoute > < Profile /> </ ProtectedRoute > } />
51+ < Route path = "/import/splitwise" element = { < ProtectedRoute > < SplitwiseImport /> </ ProtectedRoute > } />
52+ < Route path = "/import/splitwise/select-groups" element = { < ProtectedRoute > < SplitwiseGroupSelection /> </ ProtectedRoute > } />
53+ < Route path = "/import/splitwise/callback" element = { < ProtectedRoute > < SplitwiseCallback /> </ ProtectedRoute > } />
54+
55+ < Route path = "*" element = { < Navigate to = { isAuthenticated ? "/dashboard" : "/login" } /> } />
56+ </ Routes >
57+ </ Suspense >
5358 ) ;
5459}
5560
0 commit comments