Skip to content

Commit 45e9acd

Browse files
committed
fix: 404
1 parent 6d0ce0a commit 45e9acd

3 files changed

Lines changed: 24 additions & 43 deletions

File tree

404.html

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +0,0 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta charset="utf-8">
5-
<title>Feekool</title>
6-
<script type="text/javascript">
7-
// Single Page Apps for GitHub Pages
8-
// MIT License
9-
// https://github.com/rafgraph/spa-github-pages
10-
// This script takes the current url and converts the path and query
11-
// string into just a query string, and then redirects the browser
12-
// to the new url with only a query string and hash fragment,
13-
// e.g., https://www.foo.tld/one/two?a=b&c=d#qwe, becomes
14-
// https://www.foo.tld/?/one/two&a=b~and~c=d#qwe
15-
// Note: this 404.html file must be at least 512 bytes for it to work
16-
// with Internet Explorer (it is currently > 512 bytes)
17-
18-
// If you're creating a Project Pages site and NOT using a custom domain,
19-
// then set pathSegmentsToKeep to 1 (enterprise users may need to set it to > 1).
20-
// This way the code will only replace the route part and not the real repository name,
21-
// which is what we want for GitHub Pages.
22-
// If you're using a custom domain, set pathSegmentsToKeep to 0.
23-
var pathSegmentsToKeep = 1;
24-
25-
var l = window.location;
26-
l.replace(
27-
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
28-
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
29-
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
30-
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
31-
l.hash
32-
);
33-
</script>
34-
</head>
35-
<body>
36-
</body>
37-
</html>

index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>GitHub Forum Platform</title>
8+
<script type="text/javascript">
9+
// Single Page Apps for GitHub Pages
10+
// MIT License
11+
// https://github.com/rafgraph/spa-github-pages
12+
// This script checks to see if a redirect is present in the query string,
13+
// converts it back to the correct url and adds it to the
14+
// browser's history using window.history.replaceState(...),
15+
// which won't cause the browser to attempt to load the new url.
16+
// When the single page app is loaded further down in this file,
17+
// the correct url will be waiting in the browser's history for
18+
// the single page app to route accordingly.
19+
(function(l) {
20+
if (l.search[1] === '/' ) {
21+
var decoded = l.search.slice(1).split('&').map(function(s) {
22+
return s.replace(/~and~/g, '&')
23+
}).join('?');
24+
window.history.replaceState(null, null,
25+
l.pathname.slice(0, -1) + decoded + l.hash
26+
);
27+
}
28+
}(window.location))
29+
</script>
830
</head>
931
<body>
1032
<div id="root"></div>

public/404.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
// Note: this 404.html file must be at least 512 bytes for it to work
1616
// with Internet Explorer (it is currently > 512 bytes)
1717

18-
// If you're creating a Project Pages site and NOT using a custom domain,
19-
// then set pathSegmentsToKeep to 1 (enterprise users may need to set it to > 1).
20-
// This way the code will only replace the route part and not the real repository name,
21-
// which is what we want for GitHub Pages.
22-
// If you're using a custom domain, set pathSegmentsToKeep to 0.
23-
var pathSegmentsToKeep = 1;
18+
// For user GitHub Pages (username.github.io), set pathSegmentsToKeep to 0.
19+
var pathSegmentsToKeep = 0;
2420

2521
var l = window.location;
2622
l.replace(

0 commit comments

Comments
 (0)