|
4 | 4 | <meta charset="utf-8"> |
5 | 5 | <title>Redirecting...</title> |
6 | 6 | <script type="text/javascript"> |
7 | | - // Redirect to the root of the application |
8 | | - // The React app's BrowserRouter will then handle the path |
9 | | - window.location.replace('/'); |
| 7 | + // Single Page Apps for GitHub Pages |
| 8 | + // MIT License |
| 9 | + // https://github.com/rafgraph/spa-github-pages |
| 10 | + // This script takes the current URL and converts the path and query |
| 11 | + // string into just a query string, and then redirects the browser |
| 12 | + // to the new URL with the query string and hash fragment, but no |
| 13 | + // path, to load the single page app's index.html root. |
| 14 | + (function(){ |
| 15 | + var path = window.location.pathname; |
| 16 | + var query = window.location.search; |
| 17 | + var fragment = window.location.hash; |
| 18 | + |
| 19 | + // Only redirect if not already on index.html and not a direct file request |
| 20 | + if (path !== '/index.html' && !path.endsWith('.html')) { |
| 21 | + // Store the original path in sessionStorage |
| 22 | + sessionStorage.setItem('redirectPath', path + query + fragment); |
| 23 | + // Redirect to index.html |
| 24 | + window.location.replace('/index.html'); |
| 25 | + } else if (sessionStorage.getItem('redirectPath')) { |
| 26 | + // If we are on index.html and there's a stored redirectPath, |
| 27 | + // then replace the current history state with the stored path |
| 28 | + window.history.replaceState(null, null, sessionStorage.getItem('redirectPath')); |
| 29 | + sessionStorage.removeItem('redirectPath'); |
| 30 | + } |
| 31 | + })(); |
10 | 32 | </script> |
11 | 33 | </head> |
12 | 34 | <body> |
|
0 commit comments