diff --git a/lib/app-router.js b/lib/app-router.js index 4091102..d25423a 100644 --- a/lib/app-router.js +++ b/lib/app-router.js @@ -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) + }) }) } })