Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#issue 187 lazy load - dynamic import #218

Merged
merged 5 commits into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { TEXT_KEYS } from 'src/resources/texts'
import { Navigate, Route, Routes } from 'react-router-dom'

import DashboardPage from '../pages/dashboard/DashboardPage'
import TimelinePage from '../pages/TimelinePage'
import GapsPage from '../pages/GapsPage'
import GapsPatternsPage from '../pages/gapsPatterns'
import RealtimeMapPage from '../pages/RealtimeMapPage'
import SingleLineMapPage from '../pages/SingleLineMapPage'
import About from '../pages/About'
import React, { lazy, Suspense } from 'react'
const DashboardPage = lazy(() => import('../pages/dashboard/DashboardPage'))
const TimelinePage = lazy(() => import('../pages/TimelinePage'))
const GapsPage = lazy(() => import('../pages/GapsPage'))
const GapsPatternsPage = lazy(() => import('../pages/gapsPatterns'))
const RealtimeMapPage = lazy(() => import('../pages/RealtimeMapPage'))
const SingleLineMapPage = lazy(() => import('../pages/SingleLineMapPage'))
const About = lazy(() => import('../pages/About'))
import CircularProgress from '@mui/material/CircularProgress'
Comment on lines +3 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't do the trick.
we want to wait with the loading until the user clicks the menu item - that's not what your code is doing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad.
after reading the documentation, you're 100% right.
it will solve the issue perfectly.
thanks!


import {
RadarChartOutlined,
Expand Down Expand Up @@ -85,12 +86,14 @@ const RoutesList = () => {
const RedirectToDashboard = () => <Navigate to={PAGES[0].path} replace />
const routes = PAGES.filter((r) => r.element)
return (
<Routes>
{routes.map(({ path, element }) => (
<Route key={path} path={path} element={element} />
))}
<Route path="*" element={<RedirectToDashboard />} />
</Routes>
<Suspense fallback={<CircularProgress />}>
<Routes>
{routes.map(({ path, element }) => (
<Route key={path} path={path} element={element} />
))}
<Route path="*" element={<RedirectToDashboard />} />
</Routes>
</Suspense>
)
}

Expand Down
Loading