Skip to content

Commit 202bfc2

Browse files
committed
Merge remote-tracking branch 'origin/new_demo_app_fixes' into demo_app_v2
2 parents 5d6e9ba + 8519bed commit 202bfc2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

public/404.html

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Redirecting...</title>
6+
<title>Loading...</title>
77
<script>
8-
// Single Page Application redirect for GitHub Pages
9-
// This redirects all routes to index.html so React Router can handle them
10-
const pathSegmentsToKeep = 1;
11-
const l = window.location;
12-
l.replace(
13-
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
14-
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') +
15-
'/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
16-
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
17-
l.hash
18-
);
8+
// Surge serves 404.html for unknown routes unless a 200 fallback is provided.
9+
// Instead of mutating the URL (which produced /?/… redirects), load the main
10+
// SPA shell in-place so React Router can hydrate the correct route.
11+
fetch('/index.html', { credentials: 'same-origin' })
12+
.then((response) => response.text())
13+
.then((html) => {
14+
document.open();
15+
document.write(html);
16+
document.close();
17+
})
18+
.catch(() => {
19+
window.location.replace('/');
20+
});
1921
</script>
2022
</head>
2123
<body>
22-
<p>Redirecting to the app...</p>
24+
<p>Loading the application…</p>
2325
</body>
2426
</html>

0 commit comments

Comments
 (0)