Skip to content

Commit 4d080d6

Browse files
committed
add 404 page
1 parent 75fa09f commit 4d080d6

2 files changed

Lines changed: 67 additions & 19 deletions

File tree

index.html

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>资助平台</title>
8+
<style>
9+
* {
10+
margin: 0;
11+
padding: 0;
12+
}
13+
</style>
14+
</head>
315

4-
<head>
5-
<meta charset="UTF-8">
6-
<link rel="icon" href="/favicon.ico">
7-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>资助平台</title>
9-
<style>
10-
* {
11-
margin: 0;
12-
padding: 0;
13-
}
14-
</style>
15-
</head>
16+
<body>
17+
<div id="app"></div>
18+
<script>
19+
// Restore route forwarded by public/404.html when refreshing deep links on GitHub Pages.
20+
;(function (location) {
21+
if (location.search[1] === '/') {
22+
var decoded = location.search
23+
.slice(1)
24+
.split('&')
25+
.map(function (s) {
26+
return s.replace(/~and~/g, '&')
27+
})
28+
.join('?')
1629

17-
<body>
18-
<div id="app"></div>
19-
<script type="module" src="/src/main.ts"></script>
20-
</body>
21-
22-
</html>
30+
window.history.replaceState(
31+
null,
32+
'',
33+
location.pathname.slice(0, -1) + decoded + location.hash,
34+
)
35+
}
36+
})(window.location)
37+
</script>
38+
<script type="module" src="/src/main.ts"></script>
39+
</body>
40+
</html>

public/404.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Redirecting...</title>
6+
<script>
7+
// Redirect unknown static paths to index while preserving route/query for SPA restore.
8+
// Custom domain (root deploy) should use 0. For /<repo> deploy use 1.
9+
var segmentCount = 0
10+
var location = window.location
11+
var redirectTo =
12+
location.protocol +
13+
'//' +
14+
location.hostname +
15+
(location.port ? ':' + location.port : '') +
16+
location.pathname
17+
.split('/')
18+
.slice(0, 1 + segmentCount)
19+
.join('/') +
20+
'/?/' +
21+
location.pathname.slice(1).split('/').slice(segmentCount).join('/').replace(/&/g, '~and~') +
22+
(location.search ? '&' + location.search.slice(1).replace(/&/g, '~and~') : '') +
23+
location.hash
24+
25+
location.replace(redirectTo)
26+
</script>
27+
</head>
28+
29+
<body></body>
30+
</html>

0 commit comments

Comments
 (0)