Skip to content

Commit cc4f7a9

Browse files
committed
404 issue soln1
1 parent 5d2dfb9 commit cc4f7a9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

404.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="refresh" content="0; url=./index.html" />
5+
<script type="text/javascript">
6+
var pathname = window.location.pathname;
7+
window.location.href = window.location.origin + '/index.html?redirect=' + pathname;
8+
</script>
9+
</head>
10+
<body></body>
11+
</html>

src/App.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Routes,
77
Route,
88
Navigate,
9+
useLocation
910
} from 'react-router-dom';
1011

1112
import Login from './components/login';
@@ -30,9 +31,21 @@ function App() {
3031

3132
return () => unsubscribe(); // Clean up on unmount
3233
}, []);
34+
// Handle redirects from GitHub Pages 404 fallback
35+
function RedirectWithState() {
36+
const location = useLocation();
37+
useEffect(() => {
38+
const redirectPath = new URLSearchParams(location.search).get('redirect');
39+
if (redirectPath) {
40+
window.history.replaceState({}, '', redirectPath);
41+
}
42+
}, [location]);
43+
return null;
44+
}
3345

3446
return (
3547
<Router>
48+
<RedirectWithState />
3649
<div className="App">
3750
{/* Pass user status as loggedin prop to Navbar */}
3851
<Navbar loggedin={user ? 'true' : 'false'} />

0 commit comments

Comments
 (0)