mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-17 22:44:21 +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 () {
|
constructor () {
|
||||||
super()
|
super()
|
||||||
this.routes = {}
|
this.routes = {}
|
||||||
|
this.page = null
|
||||||
}
|
}
|
||||||
|
|
||||||
unload () {
|
unload () {
|
||||||
@@ -10,6 +11,8 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load (pathname = '/', opts = {}) {
|
async load (pathname = '/', opts = {}) {
|
||||||
|
if (this.page === pathname) return
|
||||||
|
this.page = pathname
|
||||||
for (const [route, element] of Object.entries(this.routes)) {
|
for (const [route, element] of Object.entries(this.routes)) {
|
||||||
if (pathname.startsWith(route)) {
|
if (pathname.startsWith(route)) {
|
||||||
const page = pathname.slice(route.length) || '/'
|
const page = pathname.slice(route.length) || '/'
|
||||||
@@ -67,11 +70,14 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
|
|||||||
})
|
})
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
if (Pear.config.link.indexOf('pear://runtime/') === 0) {
|
const page = '/' + (Pear.config.linkData || '')
|
||||||
this.load(Pear.config.link.slice(14)).catch(console.error)
|
console.log('load', page)
|
||||||
} else {
|
this.load(page).catch(console.error)
|
||||||
this.load('/')
|
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