mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +00:00
clean demo project
This commit is contained in:
36
demo-shell-ng2/app/components/router/AuthRouterOutlet.ts
Normal file
36
demo-shell-ng2/app/components/router/AuthRouterOutlet.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { ElementRef, DynamicComponentLoader, Directive, Attribute } from 'angular2/core';
|
||||
import { Router, RouterOutlet, ComponentInstruction } from 'angular2/router';
|
||||
import {Authentication} from '../../services/authentication';
|
||||
|
||||
@Directive({selector: 'auth-router-outlet'})
|
||||
export class AuthRouterOutlet extends RouterOutlet {
|
||||
|
||||
publicRoutes: Array<string>;
|
||||
private router: Router;
|
||||
|
||||
constructor(
|
||||
_elementRef: ElementRef, _loader: DynamicComponentLoader,
|
||||
_parentRouter: Router, @Attribute('name') nameAttr: string,
|
||||
private authentication: Authentication
|
||||
) {
|
||||
super(_elementRef, _loader, _parentRouter, nameAttr);
|
||||
|
||||
this.router = _parentRouter;
|
||||
this.publicRoutes = [
|
||||
'', 'login', 'signup'
|
||||
];
|
||||
}
|
||||
|
||||
activate(instruction: ComponentInstruction) {
|
||||
if (this._canActivate(instruction.urlPath)) {
|
||||
return super.activate(instruction);
|
||||
}
|
||||
|
||||
this.router.navigate(['Login']);
|
||||
}
|
||||
|
||||
_canActivate(url) {
|
||||
return this.publicRoutes.indexOf(url) !== -1
|
||||
|| this.authentication.isLoggedIn();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user