From ffaec1661a2235e2f15824e0d3783f6d33240d08 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Mon, 26 Mar 2018 23:43:33 +0200 Subject: [PATCH] fix(router): loging --- core/src/components/router/router.tsx | 35 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/core/src/components/router/router.tsx b/core/src/components/router/router.tsx index 70c84ab4ce..237fd5c187 100644 --- a/core/src/components/router/router.tsx +++ b/core/src/components/router/router.tsx @@ -31,39 +31,46 @@ export class Router { componentDidLoad() { this.init = true; - this.onRedirectChanged(); - this.onRoutesChanged(); + console.debug('[ion-router] router did load'); + this.onRedirectChanged(undefined); + this.onRoutesChanged(undefined); } @Listen('ionRouteRedirectChanged') - protected onRedirectChanged() { + protected onRedirectChanged(ev: Event) { if (!this.init) { return; } + if (ev) { + console.debug('[ion-router] route data changed', ev.target); + } this.redirects = readRedirects(this.el); } @Listen('ionRouteDataChanged') - protected onRoutesChanged() { + protected onRoutesChanged(ev: Event) { if (!this.init) { return; } const tree = readRoutes(this.el); this.routes = flattenRouterTree(tree); - console.debug('[ion-router] route data changed', this.routes); // schedule write if (this.timer) { - cancelAnimationFrame(this.timer); + clearTimeout(this.timer); this.timer = undefined; } - this.timer = requestAnimationFrame(() => { - this.timer = undefined; - this.onPopState(); - }); + if (ev) { + console.debug('[ion-router] route data changed', ev.target); + this.timer = setTimeout(() => { + this.timer = undefined; + this.writeNavStateRoot(this.getPath(), RouterDirection.None); + }); + } else { + this.writeNavStateRoot(this.getPath(), RouterDirection.None); + } } - @Listen('window:popstate') protected onPopState() { if (window.history.state === null) { @@ -76,7 +83,7 @@ export class Router { const path = this.getPath(); console.debug('[ion-router] URL changed -> update nav', path, direction); - this.writeNavStateRoot(path, direction); + return this.writeNavStateRoot(path, direction); } @Method() @@ -87,13 +94,13 @@ export class Router { const { ids, outlet } = readNavState(document.body); const chain = routerIDsToChain(ids, this.routes); if (!chain) { - console.warn('no matching URL for ', ids.map(i => i.id)); + console.warn('[ion-router] no matching URL for ', ids.map(i => i.id)); return false; } const path = chainToPath(chain); if (!path) { - console.warn('router could not match path because some required param is missing'); + console.warn('[ion-router] router could not match path because some required param is missing'); return false; }