Skip to content

Commit d555c9d

Browse files
committed
fix: routing in react-coffee-warehouse
1 parent 4046a76 commit d555c9d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>404 page</title>
6+
<script type="text/javascript">
7+
var pathSegmentsToKeep = 2;
8+
9+
var l = window.location;
10+
l.replace(
11+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
12+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
13+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
14+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
15+
l.hash
16+
);
17+
18+
</script>
19+
</head>
20+
<body>
21+
</body>
22+
</html>

examples/react-coffee-warehouse/public/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
/>
1313
<link rel="stylesheet" href="https://unpkg.com/@progress/[email protected]/dist/all.css"></link>
1414
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
15+
<script type="text/javascript">
16+
(function(l) {
17+
if (l.search[1] === '/' ) {
18+
var decoded = l.search.slice(1).split('&').map(function(s) {
19+
return s.replace(/~and~/g, '&')
20+
}).join('?');
21+
window.history.replaceState(null, null,
22+
l.pathname.slice(0, -1) + decoded + l.hash
23+
);
24+
}
25+
}(window.location))
26+
</script>
1527
<!--
1628
Notice the use of %PUBLIC_URL% in the tags above.
1729
It will be replaced with the URL of the `public` folder during the build.

0 commit comments

Comments
 (0)