authorizer/dashboard/src/routes/index.tsx

42 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-01-19 16:50:25 +00:00
import React, { lazy, Suspense } from 'react';
2022-01-17 07:33:28 +00:00
import { Outlet, Route, Routes } from 'react-router-dom';
2022-01-17 07:33:28 +00:00
import { useAuthContext } from '../contexts/AuthContext';
import { DashboardLayout } from '../layouts/DashboardLayout';
2022-01-19 16:50:25 +00:00
const Auth = lazy(() => import('../pages/Auth'));
const Environment = lazy(() => import('../pages/Environment'));
const Home = lazy(() => import('../pages/Home'));
const Users = lazy(() => import('../pages/Users'));
export const AppRoutes = () => {
2022-01-17 07:33:28 +00:00
const { isLoggedIn } = useAuthContext();
if (isLoggedIn) {
return (
2022-01-19 16:50:25 +00:00
<Suspense fallback={<></>}>
<Routes>
<Route
element={
<DashboardLayout>
<Outlet />
</DashboardLayout>
}
>
<Route path="/" element={<Home />} />
<Route path="users" element={<Users />} />
<Route path="environment" element={<Environment />} />
</Route>
</Routes>
</Suspense>
2022-01-17 07:33:28 +00:00
);
}
return (
2022-01-19 16:50:25 +00:00
<Suspense fallback={<></>}>
<Routes>
<Route path="/" element={<Auth />} />
</Routes>
</Suspense>
2022-01-17 07:33:28 +00:00
);
};