ionic2使用根导航(rootNav)跳转

ionic2使用根导航(rootNav)跳转

在一个使用tab构建的ionic2应用程序中,如果我们直接使用NavController进行导航跳转,会将新的page压入当前tab的导航栈中。但login、signin、setting等page在业务上不应该属于当前tab,而应该从根组件进行导航,那么此时该如何做呢?
看下面的例子即可:

在一个组件中跳转到根导航中

import { Component } from '@angular/core';
import { App, ViewController } from 'ionic-angular';

@Component({
template: `
<ion-content>
<h1>My PopoverPage</h1>
<button ion-button (click)="pushPage()">Call pushPage</button>
</ion-content>
`
})
class PopoverPage {
constructor(
public viewCtrl: ViewController
public appCtrl: App
) {}

pushPage() {
this.viewCtrl.dismiss();
this.appCtrl.getRootNav().push(SecondPage);
}
}

在主组件中跳转到一个根导航

import { Component, ViewChild } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
template: '<ion-nav #myNav [root]="rootPage"></ion-nav>'
})
export class MyApp {
@ViewChild('myNav') nav: NavController
public rootPage = TabsPage;

// Wait for the components in MyApp's template to be initialized
// In this case, we are waiting for the Nav with reference variable of "#myNav"
ngOnInit() {
// Let's navigate from TabsPage to Page1
this.nav.push(Page1);
}
}

end 2017-02-08 11:32:08
参考文档: http://ionicframework.com/docs/v2/api/navigation/NavController/