Recently, I struggled with the same. I solved it like this:
In the component definition object, add the $ canActivate property:
import { MainController } from './main.controller';
export class MainComponent {
constructor() {
this.controller = MainController;
this.templateUrl = 'app/main/main.html';
this.$canActivate = (Auth) => {
'ngInject';
return Auth.redirectUnauthenticated();
};
}
}
, :
export class AuthService {
constructor($auth, UserApi, $q, $rootRouter, Storage) {
'ngInject';
this.$auth = $auth;
this.$q = $q;
this.$rootRouter = $rootRouter;
this.storage = Storage;
this.userApi = UserApi.resource;
}
isAuthenticated() {
return this.$auth.isAuthenticated();
}
redirectUnauthenticated() {
if (!this.$auth.isAuthenticated()) {
this.$rootRouter.navigate(['Login']);
return false;
}
return true;
}
}
. $auth satellizer.
, ( ), , $canActivate. , , :)