authorizer/dashboard/src/routes/index.tsx

46 lines
1.2 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>
}
>
2022-05-03 14:23:21 +00:00
<Route path="/" element={<Outlet />}>
<Route index element={<Environment />} />
<Route path="/:sec" element={<Environment />} />
</Route>
<Route path="users" element={<Users />} />
<Route path="*" element={<Home />} />
2022-01-19 16:50:25 +00:00
</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 />} />
2022-01-25 07:36:52 +00:00
<Route path="*" element={<Auth />} />
2022-01-19 16:50:25 +00:00
</Routes>
</Suspense>
2022-01-17 07:33:28 +00:00
);
};