Angular 路由保护没有在RouterStateSnapshot中指定正确的路由

Angular 路由保护没有在RouterStateSnapshot中指定正确的路由,angular,routing,angular2-guards,Angular,Routing,Angular2 Guards,我的路线上有警卫,以防止未经授权的进入。警卫检查会话,如果无效,则调用登录服务。我有如下配置的路由 const routes: Routes = [ { path: 'logon', loadChildren: './logon/logon.module#LogonModule' }, { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'home', loadChildren: './home/hom

我的路线上有警卫,以防止未经授权的进入。警卫检查会话,如果无效,则调用登录服务。我有如下配置的路由

const routes: Routes = [
    { path: 'logon', loadChildren: './logon/logon.module#LogonModule' },
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'home', loadChildren: './home/home.module#HomeModule', canActivate: [HomeGuard] },
    { path: 'forms', loadChildren: './forms/forms.module#FormsModule', canActivate: [FormsGuard] },
    { path: 'processes', component: ProcessesComponent, canActivate: [ProcessGuard] },
    { path: '**', redirectTo: 'home' }
];
来自警卫的代码片段

canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {

      // This always reports home !
      alert('Logon Guard - State = ' + state.url);

      if (this.logonService.IsLoggedOn()) {
        return true;
      } 
      else {
        // Tell the clientApp what url was in use when calling the canActivate.
        this.logonService.RedirectUrl = state.url;

        this.router.navigate(['logon']);
        return false;
      }
  }
canActivate(下一步:ActivatedRouteSnapshot,状态:RouterStateSnashot):可观察的|承诺|布尔值{
//这总是回家!
警报('Logon-Guard-State='+State.url);
if(this.logonService.IsLoggedOn()){
返回true;
} 
否则{
//告诉clientApp调用canActivate时使用了什么url。
this.logonService.RedirectUrl=state.url;
this.router.navigate(['logon']);
返回false;
}
}
我想在登录后重新路由到最初请求的路由,并尝试使用RouterStateSnapshot url获取请求的路由。但是,它始终保留默认设置中指定的路由

{路径:'',重定向到:'home',路径匹配:'full'}

因此,如果我浏览到“进程”路由,即防护中的“canActivate”将始终保留RouterStateSnapshot url属性中的“主”路由

我看到了以下类似的请求。。。

我曾经尝试过为每条路线指定一个不同的守卫的建议(出于绝望),但这不起作用。无论如何,这肯定不是答案?我应该能够在路由之间共享一个身份验证守卫

我用的是角度4