Skip to content

Commit 5bb63ab

Browse files
Fix: GitHub Pages relative URL issue
Addresses the persistent 404 errors on GitHub Pages by ensuring correct routing configuration.
1 parent 9c27ad1 commit 5bb63ab

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@
5858
<meta property="og:description" content="Especialista en odontología estética y restauradora. Sonrisas naturalmente hermosas con la más alta calidad y tecnología avanzada." />
5959
<meta property="og:type" content="website" />
6060

61+
<!-- Start Single Page Apps for GitHub Pages -->
62+
<script type="text/javascript">
63+
// Single Page Apps for GitHub Pages
64+
// MIT License
65+
// https://github.com/rafgraph/spa-github-pages
66+
// This script checks to see if a redirect is present in the query string,
67+
// converts it back into the correct url and adds it to the
68+
// browser's history using window.history.replaceState(...),
69+
// which won't cause the browser to attempt to load the new url.
70+
// When the single page app is loaded further down in this file,
71+
// the correct url will be waiting in the browser's history for
72+
// the single page app to route accordingly.
73+
(function(l) {
74+
if (l.search[1] === '/' ) {
75+
var decoded = l.search.slice(1).split('&').map(function(s) {
76+
return s.replace(/~and~/g, '&')
77+
}).join('?');
78+
window.history.replaceState(null, null,
79+
l.pathname.slice(0, -1) + decoded + l.hash
80+
);
81+
}
82+
}(window.location))
83+
</script>
84+
<!-- End Single Page Apps for GitHub Pages -->
6185
</head>
6286

6387
<body>

public/404.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Dra. Liz Cheng - Odontología Estética y Restauradora</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 folder.
21+
// For example, if your site is at username.github.io/repo-name, then set
22+
// pathSegmentsToKeep to 1 so "/repo-name" is not replaced.
23+
// For username.github.io sites, set pathSegmentsToKeep to 0.
24+
var pathSegmentsToKeep = 0;
25+
26+
var l = window.location;
27+
l.replace(
28+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
29+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
30+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
31+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
32+
l.hash
33+
);
34+
</script>
35+
</head>
36+
<body>
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)