I want to add a back button in Ionic4(Angular 7). But I can't find the proper method in Angular Router.
import {Router} from '@angular/router';
How do we go back when clicking a button, in the ponent handler? I'd like to implement it using '@angular/router' not '@angular/mon' => Location
I want to add a back button in Ionic4(Angular 7). But I can't find the proper method in Angular Router.
import {Router} from '@angular/router';
How do we go back when clicking a button, in the ponent handler? I'd like to implement it using '@angular/router' not '@angular/mon' => Location
Share Improve this question edited Dec 5, 2019 at 8:19 Peter Haddad 80.9k25 gold badges145 silver badges146 bronze badges asked Apr 10, 2019 at 14:45 ValeriValeri 1,1425 gold badges15 silver badges32 bronze badges 3- stackoverflow./questions/35446955/how-to-go-back-last-page – nircraft Commented Apr 10, 2019 at 14:46
- Possible duplicate of Angular 5 - Which should I use to navigate backward - href or location.back()? – nircraft Commented Apr 10, 2019 at 14:46
- I want to go back without using Location, just with @angular/router. – Valeri Commented Apr 10, 2019 at 14:48
3 Answers
Reset to default 7Since 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/mon
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.