Skip to content

Commit fc7cab3

Browse files
committed
fix: keep params in url for github pages
1 parent eef2c8a commit fc7cab3

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

docs/404.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@
2222
</head>
2323
<body>
2424
<script>
25+
// Sauvegarder le chemin et les paramètres d'URL
2526
const path = window.location.pathname.slice(1);
26-
localStorage.setItem('path', path);
27-
window.location.href='../';
27+
const queryParams = window.location.search;
28+
const hash = window.location.hash;
29+
30+
// Stocker le chemin et les paramètres dans le sessionStorage
31+
sessionStorage.setItem('spa-path', path);
32+
sessionStorage.setItem('spa-query', queryParams);
33+
sessionStorage.setItem('spa-hash', hash);
34+
35+
// Rediriger vers la racine du site
36+
window.location.href = '/vue3-roulette/';
2837
</script>
2938
</body>
3039
</html>

docs/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
</head>
3333
<body>
3434
<div id="app"></div>
35+
<script>
36+
// Récupérer les informations stockées par la page 404.html
37+
const spaPath = sessionStorage.getItem('spa-path');
38+
const spaQuery = sessionStorage.getItem('spa-query');
39+
const spaHash = sessionStorage.getItem('spa-hash');
40+
41+
// Si des informations ont été stockées, reconstruire l'URL et rediriger
42+
if (spaPath) {
43+
// Nettoyer le sessionStorage
44+
sessionStorage.removeItem('spa-path');
45+
sessionStorage.removeItem('spa-query');
46+
sessionStorage.removeItem('spa-hash');
47+
48+
// Reconstruire l'URL et rediriger
49+
const url = '/' + spaPath + (spaQuery || '') + (spaHash || '');
50+
window.history.replaceState(null, null, url);
51+
}
52+
</script>
3553

3654
</body>
3755
</html>

index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@
2929
</head>
3030
<body>
3131
<div id="app"></div>
32+
<script>
33+
// Récupérer les informations stockées par la page 404.html
34+
const spaPath = sessionStorage.getItem('spa-path');
35+
const spaQuery = sessionStorage.getItem('spa-query');
36+
const spaHash = sessionStorage.getItem('spa-hash');
37+
38+
// Si des informations ont été stockées, reconstruire l'URL et rediriger
39+
if (spaPath) {
40+
// Nettoyer le sessionStorage
41+
sessionStorage.removeItem('spa-path');
42+
sessionStorage.removeItem('spa-query');
43+
sessionStorage.removeItem('spa-hash');
44+
45+
// Reconstruire l'URL et rediriger
46+
const url = '/' + spaPath + (spaQuery || '') + (spaHash || '');
47+
window.history.replaceState(null, null, url);
48+
}
49+
</script>
3250
<script type="module" src="/pages/main.js"></script>
3351
</body>
3452
</html>

public/404.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@
2222
</head>
2323
<body>
2424
<script>
25+
// Sauvegarder le chemin et les paramètres d'URL
2526
const path = window.location.pathname.slice(1);
26-
localStorage.setItem('path', path);
27+
const queryParams = window.location.search;
28+
const hash = window.location.hash;
29+
30+
// Stocker le chemin et les paramètres dans le sessionStorage
31+
sessionStorage.setItem('spa-path', path);
32+
sessionStorage.setItem('spa-query', queryParams);
33+
sessionStorage.setItem('spa-hash', hash);
34+
35+
// Rediriger vers la racine du site
2736
window.location.href='../';
2837
</script>
2938
</body>

0 commit comments

Comments
 (0)