I am looking for the best way to not screw up the back functionality of the browser if a resolve for an angular route fails. Right now I am doing the following:
$location.path(lastUrls[0]);
$location.replace();
window.history.back();
While this works I would like to know if there might be a better solution available. If my url history looks like this:
www.example.com -> www.example.com/items -> www.example.com/items/123
and if item 123 has a resolve for that item and it returns a 404 error then my browser history looks like this:
www.example.com -> www.example.com/items -> www.example.com/items
however because I have the window.history.back(); call, the browser is at the 2nd to last item in the history, not the last one. That back() call is in there so if the user does hit the back button, they are going to be taken to the page they expect where if I didn't have the call to back(), it would just bring them back to the page they are current on because now there are two of them in the history.
Is the way I am doing this the best possible way or is there a better way within angular?