import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , Router } from '@angular/router' ; import { LocalStorageService } from 'ng2-webstorage' ; /**
 * This class implements a guard for routes that require successful authentication.
 */ @ Injectable ( ) export class NickGuard implements CanActivate { param { LocalStorageService } localStorage param { Router } router constructor ( private localStorage , private router ) { } param { ActivatedRouteSnapshot } route param { RouterStateSnapshot } state returns { boolean } canActivate ( route , state ) { if ( ! ! this . localStorage . retrieve ( 'nick' ) ) { return true ; } this . router . navigate ( [ '/chat/entry' ] ) ; return false ; } }