bia-framework
Version:
Bia Framework to work with angular 2
45 lines (33 loc) • 1.19 kB
text/typescript
/**
* Created by jd on 11/01/2016.
*/
import {Directive, Attribute, ViewContainerRef, DynamicComponentLoader} from '@angular/core';
import {Router, RouterOutlet, ComponentInstruction} from '@angular/router-deprecated';
import {AuthService} from "./AuthService.service";
({
selector: 'router-outlet'
})
export class OdisseiaRouter extends RouterOutlet
{
private lastUrl:string;
private securyRoutes:string[] = ['home'];
constructor(_viewContainerRef:ViewContainerRef,
_loader:DynamicComponentLoader,
private _router:Router,
('name') nameAttr:string,
private authService:AuthService)
{
super(_viewContainerRef, _loader, _router, nameAttr);
}
activate(instruction:ComponentInstruction)
{
var isAuth = instruction.routeData.get('auth') || false;
var url = this._router.lastNavigationAttempt;
if (isAuth)
{
// redirect to Login, may be there a better way?
this._router.navigateByUrl('/login');
}
return super.activate(instruction);
}
}