Skip to content

Commit

Permalink
corrected app.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Apr 12, 2024
1 parent ae12818 commit fbacbf2
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ import en from 'javascript-time-ago/locale/en.json'
TimeAgo.addDefaultLocale(en)
import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import routes from 'src/routes'
import { useAuthCheck } from './components/utilities/CippauthCheck'
import importsMap from './importsMap'

library.add(fas)

const dynamicImport = (path) => {
return importsMap[path] || null
}

// Containers
const DefaultLayout = React.lazy(() => import('./layout/DefaultLayout'))

// Pages
Expand All @@ -31,7 +25,6 @@ const Page500 = React.lazy(() => import('./views/pages/page500/Page500'))
const PageLogOut = React.lazy(() => import('src/views/pages/LogoutRedirect/PageLogOut'))
const Login = React.lazy(() => import('./views/pages/login/Login'))
const Logout = React.lazy(() => import('./views/pages/login/Logout'))
//we loop through the routes array, dynamicly create the component by using dynamicImport, add the component to the route array as 'component' key.

const App = () => {
return (
Expand All @@ -57,12 +50,29 @@ const App = () => {
}
>
{routes.map((route, idx) => {
const allowedRoles = route.allowedRoles
const Routecomponent = dynamicImport(route.path)
console.log('route', route)
console.log('Routecomponent', Routecomponent)
return (
route.component && (
<Route
key={`route-${idx}`}
path={route.path}
exact={route.exact}
name={route.name}
element={
<Suspense fallback={<Skeleton />}>
<Helmet>
<title>CIPP - {route.name}</title>
</Helmet>
<ErrorBoundary key={route.name}>
<route.component />
</ErrorBoundary>
</Suspense>
}
/>
)
)
})}
{adminRoutes.map((route, idx) => {
return (
route.component && (
<Route
key={`route-${idx}`}
Expand All @@ -76,7 +86,7 @@ const App = () => {
<title>CIPP - {route.name}</title>
</Helmet>
<ErrorBoundary key={route.name}>
<Routecomponent />
<route.component />
</ErrorBoundary>
</Suspense>
</PrivateRoute>
Expand Down

0 comments on commit fbacbf2

Please sign in to comment.