Skip to content

Commit 3dd9604

Browse files
committed
perf(router): prevent initializaing page twice
1 parent fc87875 commit 3dd9604

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/src/components/route-redirect/route-redirect.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Event, EventEmitter, Prop } from '@stencil/core';
1+
import { Component, Event, EventEmitter, Prop, Watch } from '@stencil/core';
22

33
@Component({
44
tag: 'ion-route-redirect'
@@ -39,13 +39,16 @@ export class RouteRedirect {
3939
*/
4040
@Event() ionRouteRedirectChanged!: EventEmitter;
4141

42-
componentDidLoad() {
42+
@Watch('from')
43+
@Watch('to')
44+
propDidChange() {
4345
this.ionRouteRedirectChanged.emit();
4446
}
45-
componentDidUnload() {
47+
48+
componentDidLoad() {
4649
this.ionRouteRedirectChanged.emit();
4750
}
48-
componentDidUpdate() {
51+
componentDidUnload() {
4952
this.ionRouteRedirectChanged.emit();
5053
}
5154
}

core/src/components/router/router.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ export class Router {
6666
console.debug('[ion-router] found nav');
6767

6868
await this.onRoutesChanged();
69+
}
6970

71+
componentDidLoad() {
7072
this.win.addEventListener('ionRouteRedirectChanged', debounce(this.onRedirectChanged.bind(this), 10));
7173
this.win.addEventListener('ionRouteDataChanged', debounce(this.onRoutesChanged.bind(this), 100));
72-
this.onRedirectChanged();
7374
}
7475

7576
@Listen('window:popstate')

0 commit comments

Comments
 (0)