V4 goBack to calling page

Before I began to pass params and build thing, how is it possible in v4 to goBack() without knowing what was the previous page?

Let’s say I’ve got pages A and B, both could go to C, how do I know with a goBack() in C if I should go back to A or B?

An here I mean in the angular code, not the back button

In v3, .pop() took care of that. So like I said, before I began to user providers and build custom code, is there a solution for this inside the framework?

1 Like

In ordinary Angular router apps, what I do is to inject Location and call its back() method. Might that work?

4 Likes
import { Location } from '@angular/common';

goBack() {
    this.location.back();
  }

It will navigate backward one step in the browser’s history stack using the Location service that you injected previously.

or through navcontroller

goBack(){
    this.navCtrl.goBack('/pageA');
  }
4 Likes

Location.back() is the solution, furthermore could confirm that it looks like the animation is the same as a navCtrl.goBack()

1 Like

yes with same animation

I just discovered that location.back() use in one my pages end up generating a loop in Safari

Page 1 -> Go Forward -> Page 2 -> location.back -> Page 1 do an automatic go forward -> Page 2 again

So just for the record, if you use location.back() test the behavior on Safari :wink:

To overcome this I gonna pass in my provider the route I want to execute on back