码迷,mamicode.com
首页 > 其他好文 > 详细

[Angular2 Router] Guard: CanLoad

时间:2016-12-04 06:57:29      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:class   guard   port   tor   adc   boolean   ble   this   turn   

‘canLoad‘ guard can decide whether a lazy load module can be loaded or not.

 

@Injectable()
export class CanLoadPokemon implements CanLoad {

  constructor(private authService: AuthService) {

  }
  canLoad(route: Route): Observable<boolean>|Promise<boolean>|boolean {
    return this.authService.isAuth;
  }

}

 

app.routers.ts:

{path: home, loadChildren: app/home/home.module, data: {title: Pokemon List}, canLoad: [CanLoadPokemon]},

 

So if user not login, app won‘t load home module.

[Angular2 Router] Guard: CanLoad

标签:class   guard   port   tor   adc   boolean   ble   this   turn   

原文地址:http://www.cnblogs.com/Answer1215/p/6130040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!