Reputation: 2720
I have an app in Ionic 5 using Angular in which I need to programmatically navigate from the current page to the previous page. I tried using:
this._location.back();
and it works but doesn't triggers the back navigation animation like when you navigate with <ion-back-button>
, it just switches pages. So the question is how can you programmatically navigate back on an Ionic 5 app with Angular, in a way similar to what <ion-back-button>
does?
Upvotes: 5
Views: 11907
Reputation: 106
import { Location } from "@angular/common";
constructor(private location : Location){}
this.location.back();
Common package for Location used this type in back page.
Upvotes: 1
Reputation: 163
The previous answer is correct. As stated by the developers of Ionic here:
https://github.com/ionic-team/ionic-framework/issues/20448#issuecomment-586288155
it is still save to use the NavController (in combination with angular routing) and this will not be deprecated in future. The documentation on this is missing.
Upvotes: 5
Reputation: 1247
constructor(private navController: NavController){}
this.navController.back();
Upvotes: 17