Skipping views when going back or preventing going back

I have this problem in my app that I can sort of solve on my own, I just don’t know if I’m not doing something really stupid since I’m still pretty new to Ionic / Angular / UI-router.

It’s slightly more complicated but, to simplify, lets say my app is a generic fitness app.

You have predefined set of workouts (list 1) and another set of different workouts (list 2). From each list you can click and view detail of that workout (detail 1 or detail 2). From workout detail view I can display list of exercises included in that workout (ie. “even more details” in a diagram below) - this is the same list for all different types of workouts so I’m using one common view.

This is the diagram that shows how user can move through my app:

Obviously I can go back from exercises back to workout details, from workout details back to list of workouts and from that back to home.

From Detail 1 or 2 screen I can start the workout which transitions me to “countdown” screen. There is a timer and beeping - do push-ups for 20 seconds, 3, 2, 1, beep, do crunches for 30 seconds, 3, 2, 1, beep, etc…

Once timer is running, there is no back button, you can’t go back from Countdown to Detail. Either countdown eventually runs to zero or you press “End workout button” and app moves to the “Done” screen where you are praised for your hard work :slight_smile: Again, there is no going back from “Done” to “Countdown” - that route is closed. On “Done” screen I press the “OK” button and app moves back to the list I originally came from. On “List” screen there is a back button but it must not take me back to previous screen (ie. “Done”) but instead should take me back to Home (defacto parent view for List).

The only way I can achieve moving through my app like that is, to my knowledge, just completely ignoring ion-nav-back-button functionality and instead using normal button with back arrow in navbar that I manually point to where I need it. Ie. from List 1 or List 2 I just hardcode my own back button to always go Home.

Now finally my question:
Is this the only way or is it completely stupid and there’s a better way how to achieve this? The way I do it feels very wrong but I don’t know any better.

I’m afraid, that by using $state.go(…) and never going back, I’m building ever increasing history that never gets cleared. Can I cleared that manualy? How? And should I?

I also need to prevent default behaviour of hardware back button on Android. How do I do that?

Sorry for the long post. Huge thanks in advance for all your potential attempts to help me :blush:

This is now available in nightlies using $ionicGoBack(amount):

Big thanks to @adam for this!

Ah, fantastic news! Big thanks to Adam, indeed. And thank you Ash for letting me know.

1 Like

is there an other way to go back i.e 2 steps
cant switch to the nightly at the moment

have to think before posting :slight_smile:

too easy window.history.go(-2);

What version do you have?

We just upgraded our behemoth of an app from beta 12 to rc4 and it was well worth it. I recommend doing it for performance benefits and bug fixes.

At any rate, in our beta 12 version we didn’t have cached views so it was non-trivial. We used

$state.go('', { location: 'replace' });

But there were still a few issues and things were still kind of flaky. Just depends on your setup.

Hope this helps :smile:

Im on beta 14 tried rc 1 but it was not good
may i try rc 4 now