Skip to content

Commit 067c4f8

Browse files
author
幾米
committed
修正history记录
第一次打开不应该运行handleHistory,history.state应为null;只有变化之后才会进行记录。
1 parent 8deb741 commit 067c4f8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎box/chavy.boxjs.html‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,6 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
18411841
} else {
18421842
this.path = defview
18431843
}
1844-
this.handleHistory(this.path)
18451844
// 监听浏览器后退事件
18461845
window.addEventListener('popstate', (e) => (this.path = e.state.url), false)
18471846
// 如果后端没有渲染数据, 则发出请求获取数据
@@ -1909,10 +1908,13 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
19091908
this.ui.isWaitToggleSearchBar = false
19101909
}, 1000),
19111910
handleHistory(path) {
1912-
const state = { title: 'BoxJs', url: path }
1911+
const { hash } = window.location.href;
1912+
const state = { title: 'BoxJs', url: '/' + (hash ? hash : '#/') }
19131913
if (!history.state) {
19141914
history.replaceState(state, '')
19151915
}
1916+
1917+
state.url = path;
19161918
history.pushState(state, '', path)
19171919
},
19181920
// 页面返回

0 commit comments

Comments
 (0)