Skip to content

Commit fab4fe4

Browse files
committed
添加错误页
1 parent 215e069 commit fab4fe4

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

src/layouts/ErrorLayout.astro

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
import "../styles/global.css";
3+
import { ClientRouter } from "astro:transitions";
4+
const { title } = Astro.props;
5+
---
6+
7+
<html lang="zh">
8+
<head>
9+
<meta charset="utf-8" />
10+
<link rel="icon" href="/favicon.svg" type="image/svg" />
11+
<link rel="sitemap" href="/sitemap-index.xml" />
12+
<script src="../scripts/swUnregister.ts"></script>
13+
<ClientRouter />
14+
<meta name="viewport" content="width=device-width, initial-scale=1" />
15+
<meta name="description" content="这是一个错误页面" />
16+
<meta name="keywords" content="错误,error" />
17+
<meta name="author" content="LingLambda" />
18+
<!-- 统一不同浏览器的默认样式 -->
19+
<link
20+
rel="stylesheet"
21+
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
22+
integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w=="
23+
crossorigin="anonymous"
24+
referrerpolicy="no-referrer"
25+
/>
26+
<title>Ling的小窝{title ? ` - ${title}` : ""}</title>
27+
</head>
28+
<body>
29+
<div id="container">
30+
<slot>出错了!</slot>
31+
<!-- <hr style="width:600px;color:#808080; margin-top: 1rem;" /> -->
32+
</div>
33+
</body>
34+
</html>
35+
36+
<style>
37+
* {
38+
box-sizing: border-box; /* 确保所有元素的宽高包含 padding 和 border */
39+
}
40+
41+
html {
42+
background-color: rgb(250, 252, 254);
43+
}
44+
45+
html,
46+
body {
47+
margin: 0;
48+
padding: 0;
49+
height: 100%; /* 确保body和html占满全屏 */
50+
margin: 0;
51+
}
52+
53+
h1 {
54+
font-size: 2rem;
55+
}
56+
57+
img {
58+
max-width: 36rem;
59+
}
60+
61+
.gopher {
62+
align-self: flex-end;
63+
}
64+
</style>

src/pages/404.astro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
import ErrorLayout from "../layouts/ErrorLayout.astro";
3+
---
4+
5+
<ErrorLayout title="404">
6+
<h1>这里啥都没有 - 404</h1>
7+
</ErrorLayout>
8+
9+
<style></style>

src/pages/500.astro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
import ErrorLayout from "../layouts/ErrorLayout.astro";
3+
---
4+
5+
<ErrorLayout title="500">
6+
<h1>爆炸了! - 500</h1>
7+
</ErrorLayout>
8+
9+
<style></style>

0 commit comments

Comments
 (0)