Prevent a route from being added to history

I have a profile page that includes 5 subviews simmilar to a tab-bar
The parent page is an abstract (.profile) and the content are subviews (.profile.info, .profile.images, etc)
Now I would like that when a user clicks the back button to go back to the page where he came from (can be from multiple pages) so i dont want to register each individual page in the history.

Could someone pls explain how I can go about doing this?

Hey,

use $location.replace() to do that.
Greetz, bengtler.

Hey bengtler,

where do i put this? I’ve tried to add it in the sub-view’s controller but it just shows a blank page.

update: it seems that I had forgotten to add the $location as dependancy on the controller. Doing so fixed the blank page but still the navigation problem persists.

update 2: It seems that it actually does work when using the back-button on the browser but not when I click the header back button used in ios. So any ideas how to solve this problem on the header?

The problem is, that the ionic backbutton has a different behaviour.

the nav-bar-back-button does not know anything about replacing a state or does not recognize that you made a replace.
@mhartington
This would be nice if this would work ^^.

An easy solution:
Use your own Button in the Navbar for Back navigation.

Thats exactly what I did! I used $location.replace() in each subview so the back button would work nicely on the device and the browser and then on the header I created a button that calls $window.history.back();

It works like a charm :smile:

bengtler thanx for your help, very much appreciated.

the solution was quite easy, not knowing the inner workings of ionic is what did this so confusing.

I think information like this should be available in the documentation to make our lives easier.

Does this solution work with the former android back button (hardware on device) as well?