Skip to content

Commit

Permalink
Merge pull request #21 from Zheng-Changfu/dev
Browse files Browse the repository at this point in the history
fix: 解决部署后刷新 hash 丢失问题
  • Loading branch information
Zheng-Changfu authored Aug 18, 2024
2 parents 137b167 + 2901418 commit fbe4b98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
<script>
const urlParams = new URLSearchParams(window.location.search);
const p = urlParams.get('path');
const h = urlParams.get('hash')

if (p) {
// 假设你使用的是基于History API的路由
history.replaceState(null, '', p);
const redirectPath = h ? `${p}${h}` : p
history.replaceState(null, '', redirectPath);
}
</script>
<div id="app"></div>
Expand Down
7 changes: 3 additions & 4 deletions public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<script type="text/javascript">
// 检查是否在404页面
if (window.location.pathname !== '/index.html') {
// 获取当前路径
var pathname = window.location.pathname;
// 重定向到index.html,并将路径作为查询参数传递
window.location.replace('/index.html?path=' + pathname);
const hash = window.location.hash
const pathname = window.location.pathname;
window.location.replace(`/index.html?path=${pathname}&hash=${hash}`);
}
</script>
</head>
Expand Down

0 comments on commit fbe4b98

Please sign in to comment.