As most of angular developers know, Resolve property allows to protect access to certain pages.
Here a brief example of snippet code:
.config(['$routeProvider', 'securityAuthorizationProvider',
function ($routeProvider, securityAuthorizationProvider) {
$routeProvider.when('/test', {
templateUrl: '/myCorrespondingView.tpl.html',
controller: 'MyCorrespondingCtrl',
resolve: securityAuthorizationProvider.requireAuthenticatedUser
});
}])
Let's suppose a page containing a link called "Click here to access to protected page" (making a $location.path("/test")
under the hood).
Expectations are: when I click on it, make resolve
as being rejected
and...do not redirect to any other pages than the caller's page.
This causes to...nothing (the simple fact that user can't reach page is enough) but the URL changed to the targeted protected page.
=> myApp.com/test
(why Angular doesn't make this replacement only in case of a successful promise result ?? :(, but this is another question that I've just asked: AngularJS / Changing the URL only when corresponding template's resolve property is solved ).
Then...click again...
It seems that the resolve
remains not processed again at all.
Then...click on other link on the application (without full redirect of course), whichever you want in order to change the URL, and reclick on the protected link => Resolve
would be well processed again.
Is there an Angular mechanism that checks for the current page URL and the wanted page URL, and avoids to reprocess resolve
task if both are the same?
I really want to force the resolve
process even if the URL already corresponds to the targeted page one.
**UPDATED ******** From this post: https://stackoverflow.com/a/12429133/985949
Angular watches for a location change (whether it’s accomplished through typing in the location bar, clicking a link or setting the location through $location.path()). When it senses this change, it $broadcasts an event, “$locationChangeSuccess,” and begins the routing process.
It sounds that the check I supposed above is indeed done by $location.path
method...
Would be great if one can force the evaluation.