Skip to content

Commit f51c743

Browse files
committed
fix 404.html attempt 8
1 parent 1521c56 commit f51c743

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

public/404.html

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,31 @@
44
<meta charset="utf-8">
55
<title>Redirecting...</title>
66
<script type="text/javascript">
7-
// Redirect to the root of the application
8-
// The React app's BrowserRouter will then handle the path
9-
window.location.replace('/');
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 the query string and hash fragment, but no
13+
// path, to load the single page app's index.html root.
14+
(function(){
15+
var path = window.location.pathname;
16+
var query = window.location.search;
17+
var fragment = window.location.hash;
18+
19+
// Only redirect if not already on index.html and not a direct file request
20+
if (path !== '/index.html' && !path.endsWith('.html')) {
21+
// Store the original path in sessionStorage
22+
sessionStorage.setItem('redirectPath', path + query + fragment);
23+
// Redirect to index.html
24+
window.location.replace('/index.html');
25+
} else if (sessionStorage.getItem('redirectPath')) {
26+
// If we are on index.html and there's a stored redirectPath,
27+
// then replace the current history state with the stored path
28+
window.history.replaceState(null, null, sessionStorage.getItem('redirectPath'));
29+
sessionStorage.removeItem('redirectPath');
30+
}
31+
})();
1032
</script>
1133
</head>
1234
<body>

src/components/Footer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Footer = () => {
3333
<Link to="/logs" className="text-primary-400 hover:text-white transition-colors" onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}>Logs</Link>
3434
</div>
3535
<p className="text-sm text-gray-500">
36-
&copy; {new Date().getFullYear()} fezcode. All rights reserved. <code> v0.0.3 </code>
36+
&copy; {new Date().getFullYear()} fezcode. All rights reserved. <code> v0.0.4 </code>
3737
</p>
3838
</div>
3939
</div>

0 commit comments

Comments
 (0)