When you fire up this baby:
$location.path("mail/inbox/3")
Do remember that it traversed through when('mail') and when('mail/inbox') to reach when('/mail/inbox/:number'). The route went from mail -> inbox -> #3. This is why when you hit back it goes to mail/inbox.
This is a messy situation to fix. ng-router or ui-router are good when thing are simple, but as application grows, bugs like your are unavoidable.
In my projects I disable the html5Mode with $locationProvider.html5Mode(false);, essentially disabling the back button. And add custom back buttons inside the App for user to navigate back.
This solution helps with:
- User cant use back button at all, so he can't reach an unwanted state
- Custom back buttons can be configured or hidden at times. Event code to preform differently on same view, based on current app state.
- Hide the app internal URL from users to avoid the app being exploited for data the user is not supposed to see.
I hope this helps.