artch/angular-route-segment

How do i redirect to the previous route inside resolveFailed

Closed this issue · 1 comments

First of all, thanks for your very helpful work.

I'm currently protecting some routes with a password prompt. If the user quits that prompt, resloveFailed is triggered. However, I'm not able to execute a custom function for resolveFailed? The goal is set the route to the one the user was coming from when triggering the route change (i.e. opening the password prompt).

I tried something like this:

...
resolveFailed: {
   failed: function($window){
       console.log('here');
       $window.history.back();
   }
}
...

However, it seems that the function is never called since here is not logged? I don't really understand why?

(Note: using templateUrl in resolveFailed worked fine for me, since I don't know the templateURL for the failed route in advance I can't really use that right?)

Thanks for any help

Finally found a solution. Maybe it might help somebody in the future.

It is actually explained in the docs with one little but very important sentence that I think is easily overlooked or misunderstood.

It says:

resolveFailed is the alternate set of params which should be used if resolving failed.

where alternate set of params means all params that may also be use for resolve.
Thus, to send the user back where his was coming from on resolveFail, one would have to do the following:

 resolveFailed: {
        resolve: {
            failed : function($window,$q) {
                $window.history.back(); 
                return $q.resolve('Going back');
            }
        }
    }