mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-17 14:34:19 +01:00
wakeup focus & deep-link routing (#86)
* wakeup focus & deep-link routing * conventionalize * should be wakeups * fix
This commit is contained in:
committed by
GitHub
parent
de7975a380
commit
7629756c38
@@ -3,6 +3,7 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
|
||||
constructor () {
|
||||
super()
|
||||
this.routes = {}
|
||||
this.page = null
|
||||
}
|
||||
|
||||
unload () {
|
||||
@@ -10,6 +11,8 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
|
||||
}
|
||||
|
||||
async load (pathname = '/', opts = {}) {
|
||||
if (this.page === pathname) return
|
||||
this.page = pathname
|
||||
for (const [route, element] of Object.entries(this.routes)) {
|
||||
if (pathname.startsWith(route)) {
|
||||
const page = pathname.slice(route.length) || '/'
|
||||
@@ -67,11 +70,14 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
|
||||
})
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
if (Pear.config.link.indexOf('pear://runtime/') === 0) {
|
||||
this.load(Pear.config.link.slice(14)).catch(console.error)
|
||||
} else {
|
||||
this.load('/')
|
||||
}
|
||||
const page = '/' + (Pear.config.linkData || '')
|
||||
console.log('load', page)
|
||||
this.load(page).catch(console.error)
|
||||
Pear.wakeups(({ data }) => {
|
||||
Pear.Window.self.focus().catch(console.error)
|
||||
const page = '/' + (data || '')
|
||||
this.load(page).catch(console.error)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user