I'm having trouble when using a directive
to go back when using navigation with ui.router
. As far as I know, this problem occurs because of the way the application is structured. To identify a invalid URL
(or state) I have this:
$urlRouterProvider.otherwise(function($injector) {
var $state = $injector.get('$state');
$state.go('erro');
});
So if i try to access this url: website.com/contacttt
(supose this is an invalid url/state
), the ui.router
is going to redirect users to the error state.
In that state, if I try to use the goBack
directive
, this:
element.on('click', function() {
$window.history.back();
})
I'll be inside a loop, because the last history is the invalid one. I know I could use something like $window.history.go(-2);
but this also have a weird behavior, and if users hit the forward button they'll end up on the invalid state again.
I'd like to be able to use the same directive all over my application, this is a feature present in multiple views.
Is there any other way to solve this problem?