如果有人尝试像这样编写延迟加载并获得成功,请帮助我,我在这里遇到了问题。我创建了一个angular应用程序,并尝试使用延迟加载,但它对我没有帮助。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import {EmployeeComponent} from './employee/employee.component';
import {RegistrationComponent} from './registration/registration.component';
const routes: Routes = [
{
path:'',
component:EmployeeComponent
},
{
path:'employee/registration',
component: RegistrationComponent
}
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class HrRoutingModule { }这是我的代码,我在应用程序中绑定了路由,如下所示:
const routes: Routes = [
{
path: '',
component: LayoutComponent,
children: [
{
path: '',
component: EmployeeComponent
},
{
path: 'employee',
loadChildren: () => import('./hr/hr.module').then(m => m.HrModule)
}
]我刚刚创建了一个名为hr的子文件夹,并在该hr中添加了另外两个文件夹,如employee和registration,但在hr-routing-module.ts文件中添加了上述一段代码,并在hr-module文件中添加了上述组件,在app-routing.ts文件中添加了以下代码。那么这是正确的连接方式,还是我必须单独声明所有组件?
发布于 2021-02-25 17:36:23
在应用程序组件中
在布局组件中
在路由导入中: CommonModule、RouterModule.forChild( hrModule )、
https://stackoverflow.com/questions/66364013
复制相似问题