UNPKG

bia-framework

Version:

Bia Framework to work with angular 2

45 lines (33 loc) 1.19 kB
/** * 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"; @Directive({ selector: 'router-outlet' }) export class OdisseiaRouter extends RouterOutlet { private lastUrl:string; private securyRoutes:string[] = ['home']; constructor(_viewContainerRef:ViewContainerRef, _loader:DynamicComponentLoader, private _router:Router, @Attribute('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); } }