Angular Lazy loaded module - 使用param在我的路径中发出问题

时间:2017-12-05 16:20:32

标签: angular routes lazy-loading

我有三个模块(抱歉,它是法语): - 仪表板 - 德维斯 - 家庭。 这些模块是延迟加载的:

export const appRoutes: Routes = [
  { path: '', loadChildren: 'app/dashboard/dashboard.module#DashboardModule' },
  { path: 'devis', loadChildren: 'app/devis/devis.module#DevisModule' },
  { path: 'famille', loadChildren: 'app/famille/famille.module#FamilleModule' },
  {
    path: '404',
    component: Error404PageComponent,
    resolve: { data: Error404PageResolver }
  },
  {
    // There's a bug that's preventing wild card routes to be lazy loaded (see: https://github.com/angular/angular/issues/13848)
    // That's why the Error page should be eagerly loaded
    path: '**',
    component: Error404PageComponent,
    resolve: { data: Error404PageResolver }
  }
];


@NgModule({
  imports: [ RouterModule.forRoot(appRoutes, {
    preloadingStrategy: PreloadAllModules,
    useHash: false
  }) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule {}

我的" Famille"路径文件是这样的:

const familleRoutes: Routes = [
    {
        path: '',
        children: [
            { 
                path: ':id',
                component: FamilleComponent,     
                resolve: { utilisateur: AuthResolver, dossierFamille: DossierFamilleResolver, referentiel: ReferentielFamilleResolver, informationFamille: InformationFamilleResolver, droits: DroitFamilleResolver }
            },
            { 
                path: '', 
                component: FamilleComponent,
                resolve: { utilisateur: AuthResolver, referentiel: ReferentielFamilleResolver , droits: DroitFamilleResolver } 
            }
        ]
    }
];


@NgModule({
    imports: [RouterModule.forChild(familleRoutes)],
    providers: [AuthResolver, DossierFamilleResolver, ReferentielFamilleResolver, InformationFamilleResolver, DroitFamilleResolver, AuthService],
    exports: [RouterModule]
})
export class FamilleRoutingModule { }

我也尝试这个版本:

const familleRoutes: Routes = [
    {
        path: '',
        component: FamilleComponent,
        resolve: { utilisateur: AuthResolver, referentiel: ReferentielFamilleResolver , droits: DroitFamilleResolver }
    },
    {
        path: ':id',
        component: FamilleComponent,     
        resolve: { utilisateur: AuthResolver, dossierFamille: DossierFamilleResolver, referentiel: ReferentielFamilleResolver, informationFamille: InformationFamilleResolver, droits: DroitFamilleResolver }
    }    
];

我的" devis"路线大致相同。 每一次,它都是创建一个" famille"或者" devis"并显示一个" famille"或" devis" :FamilleComponent和DevisComponent。

const devisRoutes: Routes = [
    { 
        path: '', 
        component: DevisComponent, resolve: { utilisateur: AuthResolver, referentiel: ReferentielDevisResolver, droits: DroitsDevisResolver }
    },
    { 
        path: ':id', 
        component: DevisComponent, 
        resolve: { utilisateur: AuthResolver, devis: DevisResolver, referentiel: ReferentielDevisResolver, droits: DroitsDevisResolver }
    }
];

@NgModule({
    imports: [RouterModule.forChild(devisRoutes)],
    providers: [DevisResolver, ReferentielDevisResolver, DroitsDevisResolver, AuthResolver, AuthService],
    exports: [RouterModule]
})
export class DevisRoutingModule { }

我的问题是当我尝试访问url localhost:4200 / famille时,在我的famille.resolver中,route.params.id的值是" famille"。 我希望这个值为空。

如果我尝试网址localhost:4200 / famille / 1234567,则route.params.id的值为我的ID:1234567。

没有延迟加载模块,它工作正常。所以我不明白什么是错的。

我还有一些有线的东西。我的意思是当我试图去网址时 localhost:4200 / devis,调用类InformationFamilleResolver的方法解析!

你对这个问题有什么看法吗?

感谢您的帮助, 阿德里安

0 个答案:

没有答案