# V4 goBack to calling page

**URL:** <https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370>\
**Category:** Ionic Framework\
**Created:** [August 4, 2018, 1:23pm UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370 "2018-08-04T13:23:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [August 4, 2018, 1:23pm UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/1 "2018-08-04T13:23:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 5, 2018, 12:38am UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/2 "2018-08-05T00:38:29Z")

</div>

In ordinary Angular router apps, what I do is to inject [`Location`](https://angular.io/api/common/Location) and call its `back()` method. Might that work?

---

<div class="post-metadata">

**Author:** ![anupzone](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anupzone/32/120703_2.png) [@anupzone](https://forum.ionicframework.com/u/anupzone)\
**Post date:** [August 5, 2018, 7:11am UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/3 "2018-08-05T07:11:08Z")

</div>

```auto
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

```auto
goBack(){
    this.navCtrl.goBack('/pageA');
  }

```

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [August 5, 2018, 7:22am UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/4 "2018-08-05T07:22:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anupzone](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anupzone/32/120703_2.png) [@anupzone](https://forum.ionicframework.com/u/anupzone)\
**Post date:** [August 5, 2018, 7:42am UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/5 "2018-08-05T07:42:03Z")

</div>

yes with same animation

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [August 22, 2018, 6:54am UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/7 "2018-08-22T06:54:17Z")

</div>

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 😉

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

---

<div class="post-metadata">

**Author:** ![vmkandan](https://avatars.discourse-cdn.com/v4/letter/v/a3d4f5/32.png) [@vmkandan](https://forum.ionicframework.com/u/vmkandan)\
**Post date:** [August 16, 2019, 3:10pm UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/8 "2019-08-16T15:10:31Z")

</div>

> **[Ionic Documentation](https://beta.ionicframework.com/docs/api/back-button)**
>
> Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base and open web standards

---

<div class="post-metadata">

**Author:** ![praveen\_vishnu](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/praveen_vishnu/32/136931_2.png) [@praveen\_vishnu](https://forum.ionicframework.com/u/praveen_vishnu)\
**Post date:** [March 21, 2021, 8:34am UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/9 "2021-03-21T08:34:09Z")

</div>

@reedrichards

hey I also facing the automatic go forward on page 2 issue.

can you please explain in detail how to overcome it? I actually didn’t get you

Thanks\>

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 8:52pm UTC](https://forum.ionicframework.com/t/v4-goback-to-calling-page/137370/10 "2021-07-19T20:52:05Z")

</div>


