Newer
Older
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React, { lazy, Suspense } from 'react';
import {
Route,
Redirect,
BrowserRouter as Router,
Switch,
} from 'react-router-dom';
import { useSelector } from 'react-redux';
import ErrorBoundary from './ErrorBoundary';
import { PUBLIC_ROUTE } from './route.constants';
import Loader from '@imd/components/utility/loader';
const Dashboard = lazy(() => import('./containers/Dashboard/Dashboard'));
const publicRoutes = [
{
path: PUBLIC_ROUTE.LANDING,
exact: true,
component: lazy(() => import('@imd/containers/Pages/SignIn/SignIn')),
},
{
path: PUBLIC_ROUTE.PAGE_404,
component: lazy(() => import('@imd/containers/Pages/404/404')),
},
{
path: PUBLIC_ROUTE.PAGE_500,
component: lazy(() => import('@imd/containers/Pages/500/500')),
},
{
path: PUBLIC_ROUTE.SIGN_IN,
component: lazy(() => import('@imd/containers/Pages/SignIn/SignIn')),
},
{
path: PUBLIC_ROUTE.SIGN_UP,
component: lazy(() => import('@imd/containers/Pages/SignUp/SignUp')),
},
{
path: PUBLIC_ROUTE.FORGET_PASSWORD,
component: lazy(() =>
import('@imd/containers/Pages/ForgotPassword/ForgotPassword')
),
},
{
path: PUBLIC_ROUTE.RESET_PASSWORD,
component: lazy(() =>
import('@imd/containers/Pages/ResetPassword/ResetPassword')
),
},
{
path: PUBLIC_ROUTE.AUTH0_CALLBACK,
component: lazy(() =>
import('@imd/containers/Authentication/Auth0/Auth0Callback')
),
},
];
function PrivateRoute({ children, ...rest }) {
const isLoggedIn = useSelector(state => state.Auth.idToken);
return (
<Route
{...rest}
render={({ location }) =>
isLoggedIn ? (
children
) : (
<Redirect
to={{
pathname: '/signin',
state: { from: location },
}}
/>
)
}
/>
);
}
export default function Routes() {
return (
<ErrorBoundary>
<Suspense fallback={<Loader />}>
<Router>
<Switch>
{publicRoutes.map((route, index) => (
<Route key={index} path={route.path} exact={route.exact}>
<route.component />
</Route>
))}
<PrivateRoute path="/dashboard">
<Dashboard />
</PrivateRoute>
</Switch>
</Router>
</Suspense>
</ErrorBoundary>
);
}