I am currently monitoring events of the type $routeChangeError within a run block in my application.
$rootScope.$on("$routeChangeError", function (event, current, previous, rejection) {
if (!!previous) {
console.log(previous);
$location.path(previous.$$route.originalPath);
}
});
Using the previous parameter, I aim to navigate back to the previous page. This method works well unless the "originalPath" of "previous.$$route" includes parameters. In such cases, the "originalPath" remains untransformed.
Upon logging the previous objects, the output is as follows:
$$route: Object
...
originalPath: "/users/:id"
regexp: /^\/users\/(?:([^\/]+)?)$/
...
params: Object
id: "3"
How can I successfully set the location to the previous path along with its parameters?