Skip to content

Commit 7385158

Browse files
committed
fix(tabs): popToRoot catches the rejected promise
1 parent 8d9f374 commit 7385158

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/components/tabs/tabs.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,16 @@ export class Tabs extends Ion implements AfterViewInit {
529529

530530
} else if (tab.length() > 1) {
531531
// if we're a few pages deep, pop to root
532-
tab.popToRoot();
532+
tab.popToRoot().catch(() => {
533+
console.debug('Tabs: pop to root was cancelled');
534+
});
533535

534536
} else if (getComponent(this._linker, tab.root) !== active.component) {
535537
// Otherwise, if the page we're on is not our real root, reset it to our
536538
// default root type
537-
tab.setRoot(tab.root);
539+
tab.setRoot(tab.root).catch(() => {
540+
console.debug('Tabs: reset root was cancelled');
541+
});
538542
}
539543
}
540544
}
@@ -545,7 +549,7 @@ export class Tabs extends Ion implements AfterViewInit {
545549
*/
546550
setTabbarPosition(top: number, bottom: number) {
547551
if (this._top !== top || this._bottom !== bottom) {
548-
const tabbarEle = <HTMLElement>this._tabbar.nativeElement;
552+
var tabbarEle = <HTMLElement>this._tabbar.nativeElement;
549553
tabbarEle.style.top = (top > -1 ? top + 'px' : '');
550554
tabbarEle.style.bottom = (bottom > -1 ? bottom + 'px' : '');
551555
tabbarEle.classList.add('show-tabbar');

src/components/tabs/test/advanced/app.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ export class Tab2Page3 {
315315

316316
constructor(public navCtrl: NavController) {}
317317

318+
ionViewCanLeave() {
319+
console.log('Tab2Page3, ionViewCanLeave', false);
320+
return false;
321+
}
322+
318323
ionViewWillEnter() {
319324
console.log('Tab2Page3, ionViewWillEnter');
320325
}

src/components/tabs/test/advanced/tab2page3.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<h2>Tab 2, Page 3</h2>
55

66
<p>No Header.</p>
7+
<p>This page can't be left</p>
78

8-
<p><button ion-button (click)="navCtrl.pop()">Back to Tab 2, Page 2</button></p>
9+
<p><button ion-button navPop>Back to Tab 2, Page 2</button></p>
910
<div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div>
1011
<div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div>
1112

0 commit comments

Comments
 (0)