mirror of
https://github.com/NoCrypt/migu.git
synced 2026-01-11 20:10:22 +00:00
feat: #470 use a router for navigation, support backwards/forwards navigation
This commit is contained in:
parent
1923be429a
commit
32d1d03d11
2 changed files with 30 additions and 1 deletions
|
|
@ -113,7 +113,7 @@ apt install linux-Miru-*.deb
|
|||
|
||||
## **Building and Development**
|
||||
|
||||
*dont*
|
||||
*good luck*
|
||||
|
||||
Dependencies:
|
||||
- Node 16 or above
|
||||
|
|
|
|||
|
|
@ -14,6 +14,35 @@
|
|||
IPC.on('schedule', () => {
|
||||
page.set('schedule')
|
||||
})
|
||||
|
||||
let ignoreNext = false
|
||||
function addPage (value, type) {
|
||||
if (ignoreNext) {
|
||||
ignoreNext = false
|
||||
return
|
||||
}
|
||||
history.pushState({ type, value }, '', './?id=' + Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER).toString())
|
||||
}
|
||||
page.subscribe((value) => {
|
||||
addPage(value, 'page')
|
||||
})
|
||||
view.subscribe((value) => {
|
||||
addPage(value, 'view')
|
||||
})
|
||||
|
||||
addPage('home', 'page')
|
||||
|
||||
window.addEventListener('popstate', e => {
|
||||
const { state } = e
|
||||
if (!state) return
|
||||
ignoreNext = true
|
||||
view.set(null)
|
||||
if (state.type === 'page') {
|
||||
page.set(state.value)
|
||||
} else {
|
||||
view.set(state.value)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue