angular - Angular2 CanActivate from beta to current RC3 -


i'm trying implement in angular2, auth0 login method video. using angular2-jwt.

i read documentation, tried implement it, can't right.
tried export class navbarcomponent implements canactivate, routercanactivate(){}, canactivate(){}. i'm stuck.

what changes needed canactivate work in current rc3?

import {canactivate} 'angular2/router'; import {tokennotexpired, jwthelper} 'angular2-jwt';  ...     @canactivate (()=>tokennotexpired()) export class navbarcomponent{ ... } 

see

create service class acts guard:

import { canactivate }    '@angular/router';  export class authguard implements canactivate {   canactivate() {     console.log('authguard#canactivate called');     return true;   } } 

in new router supports dependency injection out of box

configure route use guard:

{   path: 'admin',   component: crisisadmincomponent,   canactivate: [authguard] }, 

the guard service can return observable resolves true or false

import { injectable } '@angular/core';  import { observable } 'rxjs/observable'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/delay';  @injectable() export class authservice {   isloggedin: boolean = false;    login() {     return observable.of(true).delay(1000).do(val => this.isloggedin = true);   }    logout() {     this.isloggedin = false;   } } 

the guard service needs provided other service. place example app_router_providers

export const app_router_providers = [   providerouter(routes),   authguard ]; 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -