Skip to content

Commit 6d6eebe

Browse files
committed
fix: SPA-Routing für GitHub Pages hinzugefügt
1 parent 4a4becc commit 6d6eebe

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

public/404.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Redirecting...</title>
6+
<script type="text/javascript">
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 only a query string and hash fragment.
13+
var pathSegmentsToKeep = 1;
14+
15+
var l = window.location;
16+
l.replace(
17+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
18+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
19+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
20+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
21+
l.hash
22+
);
23+
</script>
24+
</head>
25+
<body>
26+
Redirecting...
27+
</body>
28+
</html>

public/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@
2525
Learn how to configure a non-root public URL by running `npm run build`.
2626
-->
2727
<title>Flow UI Toolkit</title>
28+
29+
<!-- Start Single Page Apps for GitHub Pages -->
30+
<script type="text/javascript">
31+
// Single Page Apps for GitHub Pages
32+
// MIT License
33+
// https://github.com/rafgraph/spa-github-pages
34+
// This script checks to see if a redirect is present in the query string,
35+
// converts it back into the correct url and adds it to the
36+
// browser's history using window.history.replaceState(...),
37+
// which won't cause the browser to attempt to load the new url.
38+
// When the single page app is loaded further down in this file,
39+
// the correct url will be waiting in the browser's history for
40+
// the single page app to route accordingly.
41+
(function(l) {
42+
if (l.search[1] === '/' ) {
43+
var decoded = l.search.slice(1).split('&').map(function(s) {
44+
return s.replace(/~and~/g, '&')
45+
}).join('?');
46+
window.history.replaceState(null, null,
47+
l.pathname.slice(0, -1) + decoded + l.hash
48+
);
49+
}
50+
}(window.location))
51+
</script>
52+
<!-- End Single Page Apps for GitHub Pages -->
2853
</head>
2954
<body>
3055
<noscript>You need to enable JavaScript to run this app.</noscript>

0 commit comments

Comments
 (0)