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 component handler? I'd like to implement it using '@angular/router' not '@angular/common' => Location
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With