Skip to content

Commit e6474e2

Browse files
committed
fix: Use sessionStorage to prevent infinite redirect loops in 404.html
- Add redirect flag in sessionStorage to prevent multiple redirects - Redirect to clean path and let React Router handle routing - Fixes infinite redirect loop issue on page reload
1 parent e55b717 commit e6474e2

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

frontend/public/404.html

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,27 @@
88
(function () {
99
var l = window.location;
1010
var pathname = l.pathname;
11+
var redirectKey = "euphoric_redirect_done";
1112

12-
// If we're already on index.html, don't redirect (let React Router handle it)
13-
if (pathname === "/euphoric/index.html" || pathname === "/euphoric/") {
13+
// Check if we've already redirected (prevent loops)
14+
if (sessionStorage.getItem(redirectKey)) {
15+
sessionStorage.removeItem(redirectKey);
16+
return; // Already redirected, let React Router handle it
17+
}
18+
19+
// If we're already on index.html or base path, don't redirect
20+
if (
21+
pathname === "/euphoric/index.html" ||
22+
pathname === "/euphoric/" ||
23+
pathname === "/euphoric"
24+
) {
1425
return;
1526
}
1627

1728
// If path contains index.html multiple times, we're in a loop - stop
1829
var indexHtmlCount = (pathname.match(/index\.html/g) || []).length;
1930
if (indexHtmlCount > 1) {
20-
// Force redirect to base path
31+
sessionStorage.setItem(redirectKey, "true");
2132
l.replace("/euphoric/");
2233
return;
2334
}
@@ -26,21 +37,14 @@
2637
var route = pathname
2738
.replace(/^\/euphoric\/?/, "")
2839
.replace(/^index\.html\/?/, "");
29-
30-
// Remove any duplicate euphoric/index.html patterns
3140
route = route.replace(/euphoric\/index\.html\/?/g, "");
32-
33-
// Clean up the route
3441
route = route.replace(/\/+/g, "/").replace(/^\//, "");
3542

36-
// Redirect to index.html - React Router with basename will handle the route
37-
// The route is preserved in the URL path, React Router will match it
38-
var redirectUrl = "/euphoric/index.html" + (route ? "/" + route : "") + l.search + l.hash;
39-
40-
// Only redirect if we're not already there and not in a loop
41-
if (pathname !== redirectUrl && !pathname.includes("/index.html")) {
42-
l.replace(redirectUrl);
43-
}
43+
// Set flag and redirect to base path
44+
// React Router with basename="/euphoric" will handle the route from the original URL
45+
sessionStorage.setItem(redirectKey, "true");
46+
var targetPath = "/euphoric" + (route ? "/" + route : "");
47+
l.replace(targetPath + l.search + l.hash);
4448
})();
4549
</script>
4650
</head>

0 commit comments

Comments
 (0)