路由解析器导致路由保护程序循环

时间:2018-06-20 20:50:49

标签: angular5 angular-routing angular-router-guards angular-resolver

我正在尝试利用路由保护程序和路由解析器,两者均出于各种原因都使用了我要订阅的API调用。基本上,我的路由守卫正在检查是否有Im试图访问的页面的数据,然后我的解析器获取所述数据。

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    let url = state.url; // where i'm trying to go
    let id = route.params['id'];
    this.dsProject.getChildProjectsByParentProject(id).subscribe(
        data => {
            if (data.length < 1) {
                this.router.navigate(['/SoftwareHome']); // back to original page
            } else {
                this.router.navigate([url]);
            }
        },
        err => {
        },
        () => {
        }
    )
    return true;
}

休息

resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
    // get the current route and route state as parameters which are passed automatically
) {
    const id = route.params['id'];
    return this.dsProject.getChildProjectsByParentProject(id);
    // pass the API down to the component to be grabbed via snapshot
}

0 个答案:

没有答案