代码之家  ›  专栏  ›  技术社区  ›  BBaysinger alex

未调用角度2+路由解析程序

  •  1
  • BBaysinger alex  · 技术社区  · 7 年前

    我已经设置了一个AuthResolve类,以确保在显示路由之前完成身份验证,但由于某些原因,解析程序没有被调用。解析函数和构造函数都不是。控制台不会记录我插入的日志。我不明白这是怎么回事。

    根级路由:

    export const appRoutes: Routes = [
      {
        path: '',
        component: CallbackComponent,
        canActivate: [AuthGuardService],
        pathMatch: 'full',
        resolve: {
          auth: AuthResolve,
        },
      },
      {
        path: 'applicant', component: ApplicantViewComponent,
        canActivate: [AuthGuardService],
        children: [...applicantRoutes],
        resolve: {
          agency: AgencyResolve,
          mapping: SectionMappingResolve,
          auth: AuthResolve,
        },
      },
      {
        path: 'agency', component: AgencyViewComponent,
        canActivate: [AuthGuardService],
        children: [...agencyRoutes],
        resolve: {
          agency: AgencyResolve,
          mapping: SectionMappingResolve,
          auth: AuthResolve,
        },
      },
      {
        path: 'tos', component: TosComponent,
        canActivate: [AuthGuardService],
        resolve: {
          auth: AuthResolve,
        },
      },
      {
        path: 'eua', component: EuaComponent,
        canActivate: [AuthGuardService],
        resolve: {
          auth: AuthResolve,
        },
      }
    ];
    

    授权解决。ts:

    @Injectable()
    export class AuthResolve implements Resolve<User> {
    
      constructor(private authService: AuthService) {
        console.log('AuthResolve.constructor');
      }
    
      resolve(route: ActivatedRouteSnapshot): Observable<User> {
        console.log('AuthResolve.resolve');
        const authHandle = this.authService.handleAuthentication()
    
        authHandle.subscribe(() => {
          this.authService.scheduleRenewal();
        });
    
        return authHandle;
    
      }
    }
    

    为什么我的解决方案没有被调用?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Anshuman Jaiswal    7 年前

    从第一条路线中删除以下内容:

    canActivate: [AuthGuardService]