File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments