2017-07-17 50 views
0

這裏IM使用Angular2懶Routing.i我EmployeeComponent寫了一些canActive代碼爲員工瀝像如何禁用後canActive路線成功

{ path: 'Employee', loadChildren:"../../module/employeemodule#EmployeeModule" ,canActivate: [EmployeeComponent]}, 

我實現canActive像這樣

canActivate(): Observable<boolean> { 
     if (localStorage.getItem('currentUser')) { 
      alert('this is auth...') 
      // this.router.navigate(['/Employee/Add']); 
     } 
     else 
      this.router.navigate(['/Login/Add']); 
     return undefined; 
    } 

這裏在我將令牌存儲在瀏覽器中後,警報即將到來,但其不是重定向員工頁面

回答

1

將其更改爲,

canActivate(): Observable<boolean> | boolean { 
if (localStorage.getItem('currentUser')) 
+0

非常感謝Sajee –