File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed
Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 33 < head >
44 < meta charset ="utf-8 " />
55 < script >
6- // Redirect to index.html and keep the original path
7- sessionStorage . redirect = location . pathname + location . search ;
8- location . href = location . origin + location . pathname . replace ( / \/ [ ^ \/ ] * $ / , '/' ) + 'index.html' ;
6+ const pathname = location . pathname ;
7+ const hasExtension = / \. [ ^ \/ ] + $ / . test ( pathname ) ;
8+
9+ // Only redirect SPA routes (no extension)
10+ if ( ! hasExtension ) {
11+ const redirectUrl = encodeURIComponent ( pathname + location . search ) ;
12+
13+ // Redirect exactly once into SPA entry
14+ location . replace ( "/react-hook-form-ai/index.html?redirect=" + redirectUrl ) ;
15+ }
916 </ script >
17+ < title > 404</ title >
1018 </ head >
11- < body > </ body >
19+ < body >
20+ < h1 > 404</ h1 >
21+ </ body >
1222</ html >
Original file line number Diff line number Diff line change @@ -4,11 +4,12 @@ import { BrowserRouter } from "react-router-dom";
44import App from "./App" ;
55import "./index.css" ;
66
7- // Restore intended SPA route after GitHub Pages redirect fallback
8- if ( sessionStorage . redirect ) {
9- const redirectUrl = sessionStorage . redirect as string ;
10- delete sessionStorage . redirect ;
11- history . replaceState ( null , "" , redirectUrl ) ;
7+ // Read redirect query param
8+ const params = new URLSearchParams ( location . search ) ;
9+ const redirect = params . get ( "redirect" ) ;
10+
11+ if ( redirect ) {
12+ history . replaceState ( null , "" , redirect ) ;
1213}
1314
1415ReactDOM . render (
You can’t perform that action at this time.
0 commit comments