Skip to content

Commit 2bac202

Browse files
committed
Updates
1 parent 5d29ef1 commit 2bac202

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

404.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515
var path = window.location.pathname;
1616
var query = window.location.search;
1717
var fragment = window.location.hash;
18+
1819
// If the path is not / and doesn't end with .html, redirect to /index.html
19-
if (path !== '/' && !path.endsWith('.html')) {
20-
window.history.replaceState(null, null, path + query + fragment);
20+
// This is a more robust check to ensure we only redirect when necessary
21+
if (path !== '/' && !path.endsWith('.html') && !path.endsWith('/')) {
22+
// Store the original path in sessionStorage
23+
sessionStorage.setItem('redirectPath', path + query + fragment);
24+
// Redirect to index.html
2125
window.location.replace('/index.html');
26+
} else if (sessionStorage.getItem('redirectPath')) {
27+
// If we are on index.html and there's a stored redirectPath,
28+
// then replace the current history state with the stored path
29+
window.history.replaceState(null, null, sessionStorage.getItem('redirectPath'));
30+
sessionStorage.removeItem('redirectPath');
2231
}
2332
})();
2433
</script>

0 commit comments

Comments
 (0)