Angular 2嵌套路由解析执行

前端之家收集整理的这篇文章主要介绍了Angular 2嵌套路由解析执行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
例如,如果我有以下路线组织:
const appRoutes: Routes = [
    {
        path: "",component: AppComponent,resolve: {
            app: AppResolver
        },children: [
            {
                path: "",component: NestedComponent,resolve: {
                    subscribers: NestedResolver
                }
            }
        ]
    }
];

和以下解析器:

export class AppResolver implements Resolve<any> {
    constructor(private appService: AppService) {}
    resolve(route: ActivatedRouteSnapshot,state: RouterStateSnapshot): Observable<any> {
        return this.appService.getAppData();
    }
}
export class NestedResolver implements Resolve<any> {
    constructor(private nestedService: NestedService) {}
    resolve(route: ActivatedRouteSnapshot,state: RouterStateSnapshot): Observable<any> {
        console.log(route.parent.data); //when this is executed route.parent.data is empty :(
        return this.nestedService.getNestedData();
    }
}

应用程序引导后,NestedResolver和AppResolver将首先执行并并行发出请求.

我们可以更改代码并实现NestedResolver等待AppResolver解析并可以访问AppResolver解析数据吗?

Angular 2 RC6,Angular router 3.0.0-rc.2

我知道这个问题很老了,以防万一有人偶然发现它(像我一样).

这是一个已知的错误,它已被修复.只需将您的路由器版本更新为高于或等于2.1.0的版本,您应该好好去.这里参考的是相关的issue on githubassociated fix

原文链接:/angularjs/142085.html

猜你在找的Angularjs相关文章