Question about how the back button works

New to forums probably doing a lot wrong.
I navigate as below…
From TabA to Page1(shift for group) then to Page2(client list) then to Page1(shift for client)
the back button will now take me to Tab A not Page 2

Is this expected and is there a workaround that would take me to Page2?
Thanks and sorry if doing this wrong

It’s hard to say for certain without seeing your code. However, I will assume you have this routing setup:

/tabA/page1/page2/page1

In this case this would be the correct behavior. Ionic caches views in the DOM so we can offer features such as swipe to go back on iOS.

For example, if you wanted to swipe back from Page B to Page A, Page A would need to exist in the DOM ahead of time.

However, to make sure we are not unnecessarily creating new views we reuse views based on the URL.

So in this case, the second time you route to /page1 we reuse the first /page1 component instance. As far as Ionic can tell, there is no difference between the two routes, so the same component instance can be used. This is how native mobile apps work too to avoid a situation where a user can route infinitely to the same page.

Another way to think of this is the route flow I described above is the same as doing the following:

/tabA/page1/page2 → go back (via ion-back-button)

If you want Ionic to create a new instance of the Page1 component, then I recommend using parameterized URLs (I.e. /page/:id).

You Sir, Are a legend. Parameterized URL is a much better solution then what I was using. (Upgrading an Ionic 3 app and new to Ionic and Angular)

1 Like

Glad it works! We recently revamped our routing docs for Angular too: Angular Navigation: How Routing & Redirects Work in Angular Apps