How to go back in Ionic 4 How to go back in Ionic 4 typescript typescript

How to go back in Ionic 4


Since you are using ionic 4 then to go backward, you can do the following:

constructor(private navCtrl: NavController) {}btnClick(){this.navCtrl.navigateBack('/home'); } 


With Angular routing you could use the Location API:

constructor(private location: Location){}

and then when you need to navigate back call:

this.location.back();

Keep in mind that for Angular 7 you have to import Location from @angular/common


Just do the following if you wanna go back to your previous route.

constructor(private navCtrl: NavController) {}goBack(){ this.navCtrl.pop(); } 

This'll pop the current page from the navigation stack and return you to the previous page and the part of the page from where you had navigated forward.