♻️ refactor(App):lazy load routes
This commit is contained in:
+34
-5
@@ -1,24 +1,53 @@
|
|||||||
|
import React from 'react'
|
||||||
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
|
||||||
|
import { Backdrop, CircularProgress } from '@mui/material'
|
||||||
|
|
||||||
import { MainPage, ContactPage, ErrorPage, CurriculumPage, ProjectsPage } from 'components/pages'
|
import { ErrorPage } from 'components/pages'
|
||||||
|
|
||||||
|
const MainPage = React.lazy(() => import('components/pages/MainPage'))
|
||||||
|
const ProjectsPage = React.lazy(() => import('components/pages/ProjectsPage'))
|
||||||
|
const CurriculumPage = React.lazy(() => import('components/pages/CurriculumPage'))
|
||||||
|
const ContactPage = React.lazy(() => import('components/pages/ContactPage'))
|
||||||
|
|
||||||
|
const Loading = () => (
|
||||||
|
<Backdrop open={true} aria-label="loading-screen">
|
||||||
|
<CircularProgress />
|
||||||
|
</Backdrop>
|
||||||
|
)
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
element: <MainPage />,
|
element: (
|
||||||
|
<React.Suspense fallback={<Loading />}>
|
||||||
|
<MainPage />
|
||||||
|
</React.Suspense>
|
||||||
|
),
|
||||||
errorElement: <ErrorPage />,
|
errorElement: <ErrorPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/projects',
|
path: '/projects',
|
||||||
element: <ProjectsPage />,
|
element: (
|
||||||
|
<React.Suspense fallback={<Loading />}>
|
||||||
|
<ProjectsPage />
|
||||||
|
</React.Suspense>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/curriculum',
|
path: '/curriculum',
|
||||||
element: <CurriculumPage />,
|
element: (
|
||||||
|
<React.Suspense fallback={<Loading />}>
|
||||||
|
<CurriculumPage />
|
||||||
|
</React.Suspense>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/contacts',
|
path: '/contacts',
|
||||||
element: <ContactPage />,
|
element: (
|
||||||
|
<React.Suspense fallback={<Loading />}>
|
||||||
|
<ContactPage />
|
||||||
|
</React.Suspense>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user