我有一个角度6应用程序,我在其中使用延迟加载。
延迟加载效果很好。
我遇到的问题是我想根据路由在子模块中加载不同的组件。
这是我的App.Routes
export const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'login', component: HomeComponent },
{ path: 'manage/:id', loadChildren: './admin/admin.module#AdminModule' },
{ path: 'organisation-list', loadChildren: './admin/admin.module#AdminModule' }
];
因此,对于URL http:app.xxx.com/organisation-list,它会使用Routes加载Admin模块
const routes: Routes = [
{ path: 'manage/:id', component: FlowListComponent },
{ path: 'organisation-list', component: PowerComponent },
{ path: '', component: FlowListComponent }
];
现在我期待加载组件PowerComponent。这不会发生,而是加载默认的FlowListComponent?
我尝试了各种各样的东西,但我认为我对它如何运作的基本理解是错误的。
我认为你可以像这条管理路线那样做
const routes: Routes = [
{ path: '', component: PowerComponent },
{ path: 'manage/:id', component: FlowListComponent },
{ path: 'organisation-list', component: PowerComponent },
{ path: 'flow-list', component: FlowListComponent }
带路径的那个:''是默认的,我刚刚在我之前做过的项目中检查了它。
正如@abetteroliver建议我需要更改我的网址,所以现在我有
export const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'login', component: HomeComponent },
{ path: 'manage/:id', loadChildren: './admin/admin.module#AdminModule' },
{ path: 'admin', loadChildren: './admin/admin.module#AdminModule' }
];
和...
const routes: Routes = [
{ path: 'manage/:id', component: FlowListComponent },
{ path: 'organisation-list', component: PowerComponent },
{ path: 'campaign-detail/:id', component: CampaignDetailComponent },]
加载组织列表组件时,我使用url
app.嘻嘻嘻.com/admin/organ ISA tion-list