Skip to content

Commit c08fa79

Browse files
committed
404 page
1 parent 0178ef8 commit c08fa79

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

generateRoutes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ for (const route of routes) {
2020
fs.writeFileSync(filePath, routePage, "utf-8");
2121
siteMapContent += `${BASE_URL}${route.path}\n`;
2222
}
23+
fs.writeFileSync(
24+
"./dist/404.html",
25+
indexPage.replace(/<title>.+<\/title>/, `<title>404 | LNReader</title>`),
26+
"utf-8"
27+
);
2328
fs.writeFileSync("./dist/sitemap.txt", siteMapContent, "utf-8");

src/404.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Layout from "@components/Layout";
2+
import { useTheme } from "@hooks/useTheme";
3+
import { Box, Button, Divider, Typography } from "@mui/material";
4+
import Footer from "@routes/home/components/Footer";
5+
import { Link } from "react-router-dom";
6+
7+
export default function NotFound() {
8+
const theme = useTheme();
9+
return (
10+
<Layout
11+
showSideBar={false}
12+
sx={{ height: "calc(100vh - 7rem)", display: "flex" }}
13+
>
14+
<Box sx={{ display: "flex", height: "100%", flexDirection: "column" }}>
15+
<Box sx={{ flex: 1 }}>
16+
<Typography variant="h2" sx={{ fontWeight: "bold" }}>
17+
404
18+
</Typography>
19+
<Typography variant="subtitle1" sx={{ fontWeight: "bold" }}>
20+
PAGE NOT FOUND
21+
</Typography>
22+
<Typography sx={{ mt: 4, mb: 1, px: { xs: 1, md: 0 } }}>
23+
Trying to visit a page that doesn't even exist?
24+
</Typography>
25+
<Typography sx={{ color: theme.error }}>How cute !</Typography>
26+
<Box sx={{ my: 4 }}>
27+
<Link to="/">
28+
<Button variant="outlined" sx={{ borderRadius: 20 }}>
29+
Back to Home
30+
</Button>
31+
</Link>
32+
</Box>
33+
</Box>
34+
<Box sx={{ width: "100%" }}>
35+
<Divider />
36+
<Footer />
37+
</Box>
38+
</Box>
39+
</Layout>
40+
);
41+
}

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ReaderSettings from "@routes/guides/readerSettings";
1010
import Changelogs from "@routes/changelogs";
1111
import Contribute from "@routes/contribute";
1212
import Plugins from "@routes/plugins";
13+
import NotFound from "./404";
1314

1415
function App() {
1516
const theme = useTheme();
@@ -85,6 +86,7 @@ function App() {
8586
<Route path="reader-settings" element={<ReaderSettings />} />
8687
</Route>
8788
</Route>
89+
<Route path="*" Component={NotFound} />
8890
</Routes>
8991
</BrowserRouter>
9092
</ThemeProvider>

src/components/Layout/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import routes from "../../../routes.json";
99
export default function Layout({
1010
children,
1111
sx,
12+
showSideBar = true,
1213
}: {
14+
showSideBar?: boolean;
1315
sx?: SxProps;
1416
children: ReactNode;
1517
}) {
@@ -40,7 +42,7 @@ export default function Layout({
4042
...sx,
4143
}}
4244
>
43-
{location.pathname === "/" ? null : <SideBar />}
45+
{showSideBar ? <SideBar /> : null}
4446
<Box sx={{ flex: 1 }}>{children}</Box>
4547
</Box>
4648
</Box>

src/routes/home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const articles: ArticleProps[] = [
3636

3737
export default function HomePage() {
3838
return (
39-
<Layout>
39+
<Layout showSideBar={false}>
4040
<Box sx={{ pb: 16, px: { xs: 2, md: 4, lg: 16 } }}>
4141
<Banner />
4242
<Stack direction={{ sx: "column", sm: "row" }} sx={{ gap: 2 }}>

0 commit comments

Comments
 (0)