得到了一些麻烦与延迟加载。所有的URL显示我的空白页。
结构体:
- app.module.ts
- modules
- router.module.ts
- scenes
- dashboard
- dashboard.module.ts
- router.module.ts
我有
imports: [
RoutingModule,
]
在app.module.ts
routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: 'dashboard',
loadChildren: '../scenes/dashboard/dashboard.module#DashboardModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
declarations: []
})
export class RoutingModule { }
请注意,我有” ../scenes',因为它是与app.module.ts不同的文件夹。
dashboard.module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardRoutingModule } from './routing.module';
import { DashboardComponent } from './dashboard.component';
@NgModule({
imports: [
CommonModule,
DashboardRoutingModule
],
declarations: [DashboardComponent]
})
export class DashboardModule { }
routing.module.ts(仪表板):
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard.component';
const routes: Routes = [
{
path: '',
component: DashboardComponent,
children: [
{ path: 'transactions', loadChildren: './transactions#TransactionsModule' },
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [DashboardComponent]
})
export class DashboardRoutingModule { }
经过HTML的代码,我已经清空路由器电源插座,使好像连dashboard.component不会加载。
也有可能使其与使用index.ts文件。我的意思是将其与这方面的工作?
{ path: 'transactions', loadChildren: './transactions#TransactionsModule' }
交易是与出口从模块的所有数据index.ts文件的文件夹:
export * from './transactions.module';
错误:
GET http://localhost:4200/dashboard/runtime.js网:: ERR_ABORTED 404(未找到)
解:
我有分量与名称主loadChildren:“./main#MainModule”和生成块的名字是main.js,但它已经默认存在。
看来你的代码是好的。谈谈你qazxsw POI的指令?你必须有一个在你的app.component.html,一个在你的dashboard.component.html
我有我的github回购类似的例子。它有一个完整的架构首发:
router-outlet
在app.module你还需要导入子模块,是这样的。
app.module.ts
UserRoutes:
imports: [
UserRoutes,
AppRoutingModule
]
AppRoutingModule:
const userRoutesModule: Routes = [
{
path: '',
component: UserComponent,
children: [
{
path: 'domanda/edit',
canDeactivate: [EditDomandaGuard],
component: EditDomandaComponent,
},
{path: 'domanda', component: DomandaComponent},
{path: 'help', component: HelpComponent},
]
}
];
@NgModule({
imports: [RouterModule.forChild(userRoutesModule)],
exports: [RouterModule],
})
export class UserRoutes {
}
所以,你的app.module.ts应该成为:
const routes: Routes = [
{
path: '',
component: UserComponent,
children: [
{path: 'domanda/edit', component: EditDomandaComponent},
{path: 'domanda', component: DomandaComponent},
{path: 'help', component: HelpComponent},
]
},
{
path: '',
component: GuestComponent,
children: [
{path: 'help', component: HelpComponent},
{path: 'login', component: LoginComponent},
]
},
{path: '**', component: PageNotFoundComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {
}
该代码是从我的仓库在github上随意一拍,看看它是如何工作的:imports: [
DashboardRoutingModule,
RoutingModule,
]