Resolve plays a crucial role in preventing a template from being displayed based on certain conditional logic that deals with the result of a promise (whether it is solved or rejected).
In my application, I implement it like this:
.config(['$routeProvider', 'securityAuthorizationProvider',
function ($routeProvider, securityAuthorizationProvider) {
$routeProvider.when('/test', {
templateUrl: '/myCorrespondingView.tpl.html',
controller: 'MyCorrespondingCtrl',
resolve: securityAuthorizationProvider.requireAuthenticatedUser
});
}])
Therefore, this code will only display the content of /myCorrespondingView.tpl.html
if and only if
securityAuthorizationProvider.requireAuthenticatedUser
is resolved.
My goal is to avoid changing the URL to http://myApp.com/test
if the promise in the resolve
section is rejected. This is because I do not want to unnecessarily reload the previous controller if the rejection logic is to keep the user on their current page (which would require a redirection to that page).
Is there an efficient method to achieve this using the resolve
property without moving the conditional logic to the previous controller?