@@ -16,9 +16,10 @@ import {
1616 Component , Optional , ElementRef , NgZone , Renderer , ComponentFactoryResolver , ChangeDetectorRef , ErrorHandler , OnInit ,
1717 OnDestroy , ViewEncapsulation
1818} from '@angular/core' ;
19- import { Tab , App , Config , Platform , GestureController , DeepLinker , DomController } from 'ionic-angular' ;
19+ import { Tab , App , Config , Platform , GestureController , DeepLinker , DomController , NavOptions } from 'ionic-angular' ;
2020import { TransitionController } from 'ionic-angular/transitions/transition-controller' ;
2121import { CoreIonTabsComponent } from './ion-tabs' ;
22+ import { TransitionDoneFn } from 'ionic-angular/navigation/nav-util' ;
2223
2324/**
2425 * Equivalent to ion-tab, but to be used inside core-ion-tabs.
@@ -58,4 +59,35 @@ export class CoreIonTabComponent extends Tab implements OnInit, OnDestroy {
5859
5960 this . parent . remove ( this ) ;
6061 }
62+
63+ /**
64+ * Push a page to the navigation stack. this similar to parent NavController, but perform some check to make
65+ * sure one page won't open multiple time.
66+ */
67+ push ( page : any , params ?: any , opts ?: NavOptions , done ?: TransitionDoneFn ) : Promise < any > {
68+ if ( this . isTransitioning ( ) ) {
69+ // Try again later, the app is transitioning, this also happen when the page is first loaded.
70+ return new Promise < any > ( ( resolve , reject ) : void => {
71+ setTimeout ( ( ) => {
72+
73+ return this . push ( page , params , opts , done ) . then ( resolve , reject ) ;
74+ } , 250 ) ;
75+ } ) ;
76+ } else {
77+ const previousViews = this . getViews ( ) ;
78+ if ( previousViews . length > 0 ) {
79+ const previousView = previousViews [ previousViews . length - 1 ] ;
80+ const previousParam = previousView . getNavParams ( ) . data ;
81+
82+ // If the view we pushing in have same page's name and identical params, then we won't do anything.
83+ // This is Ionic issue when user clicking too fast on old device or slow internet connection.
84+ if ( previousView . name === page && JSON . stringify ( previousParam ) === JSON . stringify ( params ) ) {
85+
86+ return Promise . resolve ( ) ;
87+ }
88+ }
89+
90+ return super . push ( page , params , opts , done ) ;
91+ }
92+ }
6193}
0 commit comments