Skip to content

Commit 71d5f08

Browse files
committed
lazy load routes
1 parent 1b5c683 commit 71d5f08

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

app/src/App.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { Route, Routes } from "react-router";
2-
import About from "./views/About";
32
import Main from "./views/Main";
43
import NotFound from "./views/NotFound";
5-
import View from "./views/View";
64
import "@mantine/core/styles.css";
75
import "@mantine/dropzone/styles.css";
86
import "@mantine/code-highlight/styles.css";
7+
import { lazy, Suspense } from "react";
8+
import Loading from "./views/Loading";
9+
10+
const AboutPage = lazy(() => import("./views/About"));
11+
const ViewPage = lazy(() => import("./views/View"));
912

1013
function App() {
1114
return (
1215
<Routes>
1316
<Route path="/" element={<Main />} />
14-
<Route path="/about" element={<About />} />
15-
<Route path="/:link" element={<View />} />
17+
<Route path="/about" element={<Suspense fallback={<Loading />}><AboutPage /></Suspense>} />
18+
<Route path="/:link" element={<Suspense fallback={<Loading />}><ViewPage /></Suspense>} />
1619
<Route path="*" element={<NotFound />} />
1720
</Routes>
1821
);

app/src/views/Loading.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Container, Flex, Loader } from "@mantine/core";
2+
import Header from "../components/Header";
3+
4+
function Loading() {
5+
return (
6+
<>
7+
<Header small />
8+
<Container my={20}>
9+
<Flex w="100%" h="100%" justify="center" align="center">
10+
<Loader size="lg" />
11+
</Flex>
12+
</Container>
13+
</>
14+
);
15+
}
16+
17+
export default Loading;

0 commit comments

Comments
 (0)