When a use visits a private page unauthorized, say profile, my backend 302 redirects to a controller action that serves up the login partial in place of the profile partial.
Ok I found the solution provided by lgalfaso on Github (exact paste):
Templates are cached, if a user does not have the permissions to be in a page, then this check should be done before it reaches the controller or after, within the controller, but not on the template retrieval
If this is the way you want to follow, then you need to remove the template from the $templateCache before you call reload
So that worked for me because login template actually gets cached as the template the user was trying to access. So removing it and letting angular re-fetch the correct one for the current route worked like a charm.
var currentPageTemplate = $route.current.templateUrl;
$templateCache.remove(currentPageTemplate);
$route.reload();
I have noticed that $route.reload()
method re-instantiates everything that is setup on your $routeProvider.when("/someUrl",{controller:'SomeController',templateUrl:'SomeView.html'})
template,controller and/or any resolved promises you may have passed within the .when()
method.
Therefore; when you build your app, if you want $route.reload()
to reload all the page and re-instantiate controllers you must put everything under your <div ng-view></div>
container and include any menus or footers inside the templateUrl file.