制作一个角度全局解析器,使每条路线中的数据都可用

时间:2019-08-04 18:36:48

标签: angular angular-routing angular-resolver

我正在尝试制作一个可以提供每条路线的全局解析器……

this.activatedRoute.data =>

{
    global: {...}
    route: {...}
}

这就是我正在尝试的

const routes: Routes = [
    {
        path: '',
        resolve: { globalResolve: globalResolverService },
        children: [
            { path: '', component: HomeComponent, resolve: { home: ViewHomeResolver } },
            { path: 'getting-started', component: GettingStartedComponent },
            { path: 'expert/:slug', component: ProfileComponent, resolve: { profile: ProfileResolver } },
            { path: 'loan-types', component: Loantype2Component, resolve: { grid: Loan2Resolver } },
            { path: 'loan-types/:loan', component: LoanCategoryDetailsComponent, resolve: { loanDetails: LoanDetailsResolver } },

        ]},
];

上述结果仅对homeComponent产生期望的结果。

1 个答案:

答案 0 :(得分:1)

您的this.activatedRoute.data表示您正在访问自己的路由数据范围

要访问父数据,请使用this.activatedRoute.parent.data