-
Notifications
You must be signed in to change notification settings - Fork 19
/
App.tsx
32 lines (25 loc) · 1004 Bytes
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { lazy } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { rootPath } from '@/config';
import { RequireIsLoggedIn, useAuth } from '@/common/auth';
import { AUTH_ROUTES } from '@/features/auth/routes';
import { DASHBOARD_ROUTES } from '@/features/dashboard/routes';
const Auth = lazy(() => import('@/features/auth'));
const Dashboard = lazy(() => import('@/features/dashboard'));
const App = () => {
const { isLoggedIn } = useAuth();
const RedirectToRoot = (
<Navigate replace to={isLoggedIn ? DASHBOARD_ROUTES.index.to : AUTH_ROUTES.index.to} />
);
return (
<Routes>
<Route path={rootPath} element={RedirectToRoot} />
<Route path={AUTH_ROUTES.index.path} element={<Auth />} />
<Route element={<RequireIsLoggedIn redirectTo={rootPath} />}>
<Route path={DASHBOARD_ROUTES.index.path} element={<Dashboard />} />
</Route>
<Route path="*" element={RedirectToRoot} />
</Routes>
);
};
export default App;