Setting location based on previous parameter of $routeChangeError with AngularJS
- by Moo
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?