Skip to content

Commit 15df30e

Browse files
Fix SPA routing 404 issues on GitHub Pages
- Add custom 404.html to handle client-side routing - Implement redirect parameter system for deep links - Add .nojekyll file to disable Jekyll processing - Enhance router with beforeEach guard for redirect handling - Add styled redirect page with loading spinner - Fix URL refresh/reload 404 errors for all routes
1 parent 4a25e0a commit 15df30e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
</head>
1414
<body>
1515
<div id="app"></div>
16+
<script>
17+
// GitHub Pages SPA redirect handler
18+
(function() {
19+
const urlParams = new URLSearchParams(window.location.search);
20+
const redirect = urlParams.get('redirect');
21+
if (redirect) {
22+
// Remove the redirect parameter and navigate to the intended path
23+
history.replaceState(null, '', redirect);
24+
}
25+
})();
26+
</script>
1627
<script type="module" src="/src/main.js"></script>
1728
</body>
1829
</html>

src/router/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,22 @@ const router = createRouter({
5959
routes
6060
})
6161

62+
// Handle GitHub Pages redirect parameter
63+
router.beforeEach((to, from, next) => {
64+
// Check if this is the initial navigation with a redirect parameter
65+
if (to.path === '/' || to.path === '/explorer') {
66+
const urlParams = new URLSearchParams(window.location.search)
67+
const redirect = urlParams.get('redirect')
68+
69+
if (redirect) {
70+
// Clean up the URL and navigate to the intended route
71+
window.history.replaceState({}, '', window.location.pathname)
72+
next(redirect)
73+
return
74+
}
75+
}
76+
77+
next()
78+
})
79+
6280
export default router

0 commit comments

Comments
 (0)