Skip to content

Commit

Permalink
fix: 解决部署后刷新 hash 丢失问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheng-Changfu committed Aug 18, 2024
1 parent 2901418 commit 230b595
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
<script>
const urlParams = new URLSearchParams(window.location.search);
const p = urlParams.get('path');
const h = urlParams.get('hash')

if (p) {
const redirectPath = h ? `${p}${h}` : p
history.replaceState(null, '', redirectPath);
history.replaceState(null, '', p + window.location.hash);
}
</script>
<div id="app"></div>
Expand Down
2 changes: 1 addition & 1 deletion public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if (window.location.pathname !== '/index.html') {
const hash = window.location.hash
const pathname = window.location.pathname;
window.location.replace(`/index.html?path=${pathname}&hash=${hash}`);
window.location.replace(`/index.html?path=${encodeURIComponent(pathname)}${encodeURIComponent(hash)}`);
}
</script>
</head>
Expand Down

0 comments on commit 230b595

Please sign in to comment.