angular2 routing - How do I extend routerOutlet in angular 2 rc4 -
import { viewcontainerref, componentfactoryresolver, directive, resolvedreflectiveprovider} '@angular/core'; import { router, routeroutlet, activatedroute, routeroutletmap } '@angular/router'; @directive({ selector: 'router-outlet' }) export class applicationrouter extends routeroutlet { publicroutes: array; private parentrouter: router; private router: router; constructor(parentoutletmap: routeroutletmap, location:viewcontainerref, componentfactoryresolver: componentfactoryresolver, name: string) { super(parentoutletmap, location, componentfactoryresolver, name); this.router = _parentrouter; } activate(activatedroute: activatedroute, providers: resolvedreflectiveprovider[], outletmap: routeroutletmap) { debugger; // return super.activate(instruction); } }
i don't know types super class instantiated, purpose move authorization router level.
are interested on extending routeroutlet particular reasons or add authentication layer routes? latter change auth class "extends routeroutlet" "implements canactivate".
an example of "authenticationguard" implementation:
import { canactivate } '@angular/router'; @injectable() export class authguard implements canactivate { constructor(private authservice: authservice, private router: router) {} canactivate() { if (this.authservice.isloggedin) { return true; } this.router.navigate(['/login']); return false; } }
and on routes file(s) add "canactivate" property routes want access control layer:
//route file ... { path: 'admin', component: crisisadmincomponent, canactivate: [authguard] }, ...
simple that.
Comments
Post a Comment