首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular10中的延迟加载路由

Angular10中的延迟加载路由
EN

Stack Overflow用户
提问于 2021-02-25 15:21:56
回答 1查看 40关注 0票数 0

如果有人尝试像这样编写延迟加载并获得成功,请帮助我,我在这里遇到了问题。我创建了一个angular应用程序,并尝试使用延迟加载,但它对我没有帮助。

代码语言:javascript
复制
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 { }

这是我的代码,我在应用程序中绑定了路由,如下所示:

代码语言:javascript
复制
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文件中添加了以下代码。那么这是正确的连接方式,还是我必须单独声明所有组件?

EN

回答 1

Stack Overflow用户

发布于 2021-02-25 17:36:23

在应用程序组件中

在布局组件中

在路由导入中: CommonModule、RouterModule.forChild( hrModule )、

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66364013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档