feat: add page lazy loading
This commit is contained in:
parent
620fb77d83
commit
67319ef61d
@ -1,6 +1,8 @@
|
|||||||
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
|
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
|
||||||
import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted';
|
import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted';
|
||||||
import PieChartIcon from '@mui/icons-material/PieChart';
|
import PieChartIcon from '@mui/icons-material/PieChart';
|
||||||
|
import { CircularProgress } from '@mui/material';
|
||||||
|
import { Suspense } from 'react';
|
||||||
import { createBrowserRouter, Navigate, RouterProvider as RRDRouterProvider } from 'react-router-dom';
|
import { createBrowserRouter, Navigate, RouterProvider as RRDRouterProvider } from 'react-router-dom';
|
||||||
|
|
||||||
// todo lazy & access
|
// todo lazy & access
|
||||||
@ -12,6 +14,7 @@ import { SchedulePage, SchedulePageToolbar } from 'pages/SchedulePage';
|
|||||||
import { AsideMenuLayout } from 'widgets/AsideMenuLayout';
|
import { AsideMenuLayout } from 'widgets/AsideMenuLayout';
|
||||||
|
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
import type { RouteObject } from 'react-router-dom';
|
||||||
|
|
||||||
type PageListItem = {
|
type PageListItem = {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
@ -26,26 +29,38 @@ const pages: PageListItem[] = [
|
|||||||
icon: <PieChartIcon />,
|
icon: <PieChartIcon />,
|
||||||
title: 'Аналитика',
|
title: 'Аналитика',
|
||||||
path: '/analyze',
|
path: '/analyze',
|
||||||
Content: <AnalyzePage />,
|
Content: (
|
||||||
|
<Suspense fallback={<CircularProgress />}>
|
||||||
|
<AnalyzePage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
Toolbar: <AnalyzePageToolbar />,
|
Toolbar: <AnalyzePageToolbar />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <CalendarMonthIcon />,
|
icon: <CalendarMonthIcon />,
|
||||||
title: 'График платежей',
|
title: 'График платежей',
|
||||||
path: '/schedule',
|
path: '/schedule',
|
||||||
Content: <SchedulePage />,
|
Content: (
|
||||||
|
<Suspense fallback={<CircularProgress />}>
|
||||||
|
<SchedulePage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
Toolbar: <SchedulePageToolbar />,
|
Toolbar: <SchedulePageToolbar />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <FormatListBulletedIcon />,
|
icon: <FormatListBulletedIcon />,
|
||||||
title: 'Список платежей',
|
title: 'Список платежей',
|
||||||
path: '/payments',
|
path: '/payments',
|
||||||
Content: <PaymentsPage />,
|
Content: (
|
||||||
|
<Suspense fallback={<CircularProgress />}>
|
||||||
|
<PaymentsPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
Toolbar: <PaymentsPageToolbar />,
|
Toolbar: <PaymentsPageToolbar />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const routes = pages.map((page) => ({
|
const routes: RouteObject[] = pages.map((page) => ({
|
||||||
path: page.path,
|
path: page.path,
|
||||||
element: (
|
element: (
|
||||||
<AsideMenuLayout
|
<AsideMenuLayout
|
||||||
|
|||||||
@ -1,2 +1,5 @@
|
|||||||
export { default as AnalyzePage } from './ui/AnalyzePage.ui';
|
import { lazy } from 'react';
|
||||||
|
|
||||||
|
const LazyAnalyzePage = lazy(async () => import('./ui/AnalyzePage.ui'));
|
||||||
|
export { LazyAnalyzePage as AnalyzePage };
|
||||||
export { default as AnalyzePageToolbar } from './ui/AnalyzePageToolbar.ui';
|
export { default as AnalyzePageToolbar } from './ui/AnalyzePageToolbar.ui';
|
||||||
|
|||||||
@ -1,2 +1,5 @@
|
|||||||
export { default as PaymentsPage } from './ui/PaymentsPage.ui';
|
import { lazy } from 'react';
|
||||||
|
|
||||||
|
const LazyPaymentsPage = lazy(async () => import('./ui/PaymentsPage.ui'));
|
||||||
|
export { LazyPaymentsPage as PaymentsPage };
|
||||||
export { default as PaymentsPageToolbar } from './ui/PaymentsPageToolbar.ui';
|
export { default as PaymentsPageToolbar } from './ui/PaymentsPageToolbar.ui';
|
||||||
|
|||||||
@ -1,2 +1,5 @@
|
|||||||
export { default as SchedulePage } from './ui/SchedulePage.ui';
|
import { lazy } from 'react';
|
||||||
|
|
||||||
|
const LazySchedulePage = lazy(async () => import('./ui/SchedulePage.ui'));
|
||||||
|
export { LazySchedulePage as SchedulePage };
|
||||||
export { default as SchedulePageToolbar } from './ui/SchedulePageToolbar.ui';
|
export { default as SchedulePageToolbar } from './ui/SchedulePageToolbar.ui';
|
||||||
|
|||||||
@ -31,6 +31,7 @@ const config = (env: WebpackEnv) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (env.mode === 'production') {
|
||||||
const swPlugin = new InjectManifest({
|
const swPlugin = new InjectManifest({
|
||||||
swSrc: './src/src-sw.js',
|
swSrc: './src/src-sw.js',
|
||||||
swDest: 'sw.js',
|
swDest: 'sw.js',
|
||||||
@ -38,6 +39,7 @@ const config = (env: WebpackEnv) => {
|
|||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
baseConfig.plugins.push(swPlugin);
|
baseConfig.plugins.push(swPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
return baseConfig;
|
return baseConfig;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user