Skip to content

Commit

Permalink
perf(router): prevent initializaing page twice
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Sep 6, 2018
1 parent fc87875 commit 3dd9604
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions core/src/components/route-redirect/route-redirect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Event, EventEmitter, Prop } from '@stencil/core';
import { Component, Event, EventEmitter, Prop, Watch } from '@stencil/core';

@Component({
tag: 'ion-route-redirect'
Expand Down Expand Up @@ -39,13 +39,16 @@ export class RouteRedirect {
*/
@Event() ionRouteRedirectChanged!: EventEmitter;

componentDidLoad() {
@Watch('from')
@Watch('to')
propDidChange() {
this.ionRouteRedirectChanged.emit();
}
componentDidUnload() {

componentDidLoad() {
this.ionRouteRedirectChanged.emit();
}
componentDidUpdate() {
componentDidUnload() {
this.ionRouteRedirectChanged.emit();
}
}
3 changes: 2 additions & 1 deletion core/src/components/router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ export class Router {
console.debug('[ion-router] found nav');

await this.onRoutesChanged();
}

componentDidLoad() {
this.win.addEventListener('ionRouteRedirectChanged', debounce(this.onRedirectChanged.bind(this), 10));
this.win.addEventListener('ionRouteDataChanged', debounce(this.onRoutesChanged.bind(this), 100));
this.onRedirectChanged();
}

@Listen('window:popstate')
Expand Down

0 comments on commit 3dd9604

Please sign in to comment.