Skip to content

Commit f63900e

Browse files
author
幾米
committed
支持手势、按钮前进后退浏览历史
1 parent 650c06c commit f63900e

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎box/chavy.boxjs.html‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,9 +1524,6 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
15241524
watch: {
15251525
'ui.path': {
15261526
handler(newval, oldval) {
1527-
if (!this.isWebApp && !this.isCors) {
1528-
history.pushState({ title: 'BoxJs' }, '', newval)
1529-
}
15301527
const [, view, subview] = newval.split('/')
15311528
this.ui.view = view
15321529
this.ui.subview = subview
@@ -1675,7 +1672,10 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
16751672
this.path = defview
16761673
}
16771674
// 监听浏览器后退事件
1678-
window.addEventListener('popstate', () => (this.path = path), false)
1675+
window.addEventListener('popstate', (e) => {
1676+
console.log(e)
1677+
this.path = e.state.url
1678+
}, false)
16791679
// 如果后端没有渲染数据, 则发出请求获取数据
16801680
if (this.boxServerData) {
16811681
this.box = this.boxServerData
@@ -1694,6 +1694,14 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
16941694
onScroll(event) {
16951695
this.ui.scrollY[this.path] = event.currentTarget.scrollY
16961696
},
1697+
handleHistory(path) {
1698+
const state = { title: 'BoxJs', url: path };
1699+
1700+
if (!history.state) {
1701+
history.replaceState(state, '');
1702+
}
1703+
history.pushState(state, '', path)
1704+
},
16971705
// 页面返回
16981706
back() {
16991707
if (this.view === 'bak' && !this.bfpath) {
@@ -1724,6 +1732,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
17241732
this.$vuetify.goTo(0, { duration: 200, offset: 0 })
17251733
}
17261734
}
1735+
this.handleHistory(path)
17271736
},
17281737
// 切换应用视图
17291738
switchAppView(appId) {

0 commit comments

Comments
 (0)