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.

from angular docs router guards session


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -