Skip to content

Commit a3660b2

Browse files
Refresh fix.
1 parent b6cbb7d commit a3660b2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/BlazorPages/wwwroot/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>GitHub Pages Issue</title>
6+
7+
<!--
8+
Refresh fix for Single Page Applications (SPAs)
9+
Source: https://github.com/orgs/community/discussions/50269
10+
-->
11+
<script type="text/javascript">
12+
13+
14+
var pathSegmentsToKeep = 0;
15+
16+
var l = window.location;
17+
l.replace(
18+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
19+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
20+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
21+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
22+
l.hash
23+
);
24+
</script>
25+
</head>
26+
<body>
27+
</body>
28+
</html>

src/BlazorPages/wwwroot/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
</div>
3232
<script src="_framework/blazor.webassembly.js"></script>
3333
<script>navigator.serviceWorker.register('service-worker.js');</script>
34+
35+
<!--
36+
Refresh fix for Single Page Applications (SPAs)
37+
Source: https://github.com/orgs/community/discussions/50269
38+
-->
39+
<script type="text/javascript">
40+
(function (l) {
41+
if (l.search[1] === '/') {
42+
var decoded = l.search.slice(1).split('&').map(function (s) {
43+
return s.replace(/~and~/g, '&')
44+
}).join('?');
45+
window.history.replaceState(null, null,
46+
l.pathname.slice(0, -1) + decoded + l.hash
47+
);
48+
}
49+
}(window.location))
50+
</script>
3451
</body>
3552

3653
</html>

0 commit comments

Comments
 (0)