alexortizl
alexortizl

Reputation: 2720

Ionic 5 angular back navigation

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

Answers (3)

sumith deepan
sumith deepan

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

C. G&#228;king
C. G&#228;king

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

Neha Shah
Neha Shah

Reputation: 1247

constructor(private navController: NavController){}

 this.navController.back();

Upvotes: 17

Related Questions