sooon sooon - 1 month ago 9
TypeScript Question

ionic2 - navpop back to first page

I have a app that need to guide user to step by step. I know we can use

navpop
and
navpush
to navigate trough pages. however, How can
navpop
back to the first page?

What I tried is to
pop()
back 2 times if I have 3 pages:

//html
<button (click)="gotoAdopt()">
Back to Adopt
</button>

//component.ts
gotoAdopt(event){
// That's right, we're pushing to ourselves!
this.navCtrl.pop();
this.navCtrl.pop();///<-- pop() again to go back to first page
}


But I think there are better solution than this.

Answer

Use NavController#popToRoot

Navigate back to the root of the stack, no matter how far back that is.

Returns a promise which is resolved when the transition has completed.