Skip history entry for a particular transition

I currently have a use case for my application where the user navigates from page A to page B and completes a form which transitions them to page C. In my application, I have code in the submit-handler for a form on a page B which calls a service and then routes them to page C via a $state.go call if the service call succeeds.

For this particular series of transitions, page B is considered almost like a modal in that it shouldn’t add an entry into the history. So when the user ends up on page C, if they hit back they should go to page A. I’m looking into the $ionicViewService and the nav-clear directive, but it doesn’t seem like there’s an obvious way to accomplish this.

Does anyone have any suggestions about the best way to go forward with this feature?

This may be a hack but it sounds like on Page B you could start by checking for which state the user was coming from, and if they were coming from Page C, don’t resolve the state change and direct them to Page A instead. Do you think that would work for you?

That’s an interesting idea, and I think that would work for the issue I described. The only issue I can see is it’s also possible to go from state C to state B without using the back button via a similar global action (header button) that the user took to go from state A to state B.

I’m not totally following what you’re suggesting, but it seems like it’s unrelated to the state history at that point. What is the header button?

It’s a “Create New” button that sends them to a create page, which them takes them to a detail page if the service call succeeds.

I think I understand what you’re trying to do here. I was just in a similar situation. Here’s my tutorial: How to manipulate a back button pointer to point to a previous-previous View

1 Like

@deanq That looks perfect! I’ll give that a try.