Setting location based on previous parameter of $routeChangeError with AngularJS
        Posted  
        
            by 
                Moo
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Moo
        
        
        
        Published on 2013-10-25T19:25:09Z
        Indexed on 
            2013/10/25
            21:54 UTC
        
        
        Read the original article
        Hit count: 225
        
JavaScript
|angularjs
I'm listening on events of the type $routeChangeError in a run block of my application.
$rootScope.$on("$routeChangeError", function (event, current, previous, rejection) {
    if (!!previous) {
        console.log(previous);
        $location.path(previous.$$route.originalPath);
    }        
});
With the help of the previous parameter I would like to set the location to the previous page. This works as long as the "originalPath" of "previous.$$route" does not contain any parameters. If it contains parameters the "originalPath" is not transformed.
Logging the previous objects returns the following output:
$$route: Object
   ...
   originalPath: "/users/:id"
   regexp: /^\/users\/(?:([^\/]+)?)$/
   ...
   params: Object
      id: "3"
How can I set the location to the previous path including the parameters?
© Stack Overflow or respective owner