Skip to content

Commit 968b2c9

Browse files
committed
fix 404.html attempt 5
1 parent 0abf08e commit 968b2c9

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

public/404.html

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,24 @@
44
<meta charset="utf-8">
55
<title>Redirecting...</title>
66
<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)
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;
1718

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 of the path, and not
21-
// the real directory in which the app resides, for example:
22-
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
23-
// https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe
24-
// Otherwise, leave pathSegmentsToKeep as 0.
25-
var pathSegmentsToKeep = 0;
26-
27-
var l = window.location;
28-
l.replace(
29-
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
30-
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
31-
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
32-
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
33-
l.hash
34-
);
19+
// Only redirect if not already on index.html and not a direct file request
20+
if (path !== '/index.html' && !path.endsWith('.html')) {
21+
window.history.replaceState(null, null, path + query + fragment);
22+
window.location.replace('/index.html');
23+
}
24+
})();
3525
</script>
3626
</head>
3727
<body>

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import AnimatedRoutes from './components/AnimatedRoutes';
55

66
function App() {
77
return (
8-
<Router>
8+
<Router basename="/">
99
<Layout>
1010
<AnimatedRoutes />
1111
</Layout>

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.1 </code>
36+
&copy; {new Date().getFullYear()} fezcode. All rights reserved. <code> v0.0.2 </code>
3737
</p>
3838
</div>
3939
</div>

0 commit comments

Comments
 (0)