2017-10-11 9 views
0

자식 경로가있는 주 경로가 있고 그 자식 노드는 지연로드 모듈이며 모든 지연 모듈에 지연 경로가 있습니다. 오전 데 문제는 로딩 자식 경로가Angular 2 Routing Guard 지연된 모듈 라우팅을 사용하는 CanActivateChild

홈페이지 라우팅 코드를 여러 시간에게 호출을 방지하기 위해 주요 경로를 보호 할 때

export const PROVIDER_ROUTES: Route = { 
    path: 'provider', 
    component: ProviderComponent, 
    canActivateChild:[AuthGuard], 
    children: [ 
     { path: '', redirectTo: 'courses', pathMatch: 'full' }, 
     { path: 'courses', loadChildren: 'app/provider/course/course.module#CourseModule' }, 

    ], 

}; 

게으른로드 라우팅 코드

const routes: Routes = [ 
    { 
    path: '', 
    component: CourseListComponent, 
    resolve: { courses: CourseListResolver }, 
    children: [ 
     { 
     path: ':id', 
     component: CoursesEditComponent, 
     resolve: { organizations: AddCourseResolver } 
     }, 
     { 
     path: ':id/edit', 
     component: CoursesEditComponent, 
     resolve: { course: CourseEditResolver } 
     }, 
     { 
     path: ':id/assign/:orgId', 
     component: CourseAssignComponent, 
     resolve: { subOrganizations: LicenseAssignResolver } 
     }, 
     { 
     path: ':id/update/:orgId', 
     component: CourseAssignComponent, 
     resolve: { license: LicenseEditResolver } 
     } 

    ] 
    }, 
]; 

@NgModule({ 
    imports: [RouterModule.forChild(routes)], 
    providers: [ 
    CourseListResolver, 
    CourseEditResolver, 
    LicenseAssignResolver, 
    LicenseEditResolver, 
    AddCourseResolver 
    ], 
    exports: [RouterModule], 
}) 
export class CourseRoutingModule { } 

export const RoutedComponents = [ 
    CourseListComponent, 
    CoursesEditComponent, 
    CourseAssignComponent 
]; 

AuthGuard 코드가

입니다
export class AuthGuard implements CanActivateChild { 

    constructor(private authService: AuthService, private router: Router, private commonService:CommonService) { } 
    canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { 
    return this.authService.isUserLoggedIn().map((result: EditUser) => { 
     console.log(result); 
     if (result != null && result.organizations.length > 0) { 
     this.commonService.isAuthenticated = true; 
     return true; 
     } 
     this.commonService.isAuthenticated = false; 
     this.router.navigate(["/provider"]) 
     return false; 
    }); 

여러 번 호출되는 AuthGuard 기능 왜? 은 각 레벨에 대한 보호를 확인 있도록

enter image description here

답변

0

당신은 작동 경로의 2 개 수준을 가지고있다. 한 번 전화를 걸려면 경비원을 어린이 수준으로 이동하십시오.