【问题标题】:Angular :- components of different modules getting loadedAngular :- 加载不同模块的组件
【发布时间】:2020-06-24 02:53:02
【问题描述】:

角度概念的新蜜蜂,实际上我有 2 个模块,

1) 主模块的事件模块(它有 app.module.ts && routes.ts)

2) 用户模块,它有自己的 user.module.ts,但为此模块定义的路由(在 user.routes.ts 中)来自主 routes.ts,例如。

{ path: 'user', loadChildren: 'app/user/user.module#UserModule' }

这是在 routes.ts 中定义的

我知道的是,如果我从某个模块点击任何链接,只有与该特定模块相关的组件才会被加载,

但我在我的应用程序中看到的是,

1) 加载页面需要一些时间,即使它只是一个小应用程序

2) 当我在浏览器上查看开发人员工具(即 F12)时,在点击属于用户模块的“用户/配置文件”时,事件模块的组件也会被加载。

为什么它假设只加载用户模块的所有组件?

【问题讨论】:

    标签: angular angular-ui-router


    【解决方案1】:

    你可以创建2个路由文件

    export const Routes1: Routes1[] = [
     {
        path: '/',
        name: 'Home',
        component: HomeComponent
     },
     {
        path: '/test',
        name: 'test',
        component: TestComponent
     }
    ];
    

    并在你的 app.component.ts 中调用

    import { Component } from 'angular2/core';
    import { Routes1 } from './routeModule1';
    
    @Component({
        selector: 'my-app',
        templateUrl: 'app/app.component.html',
    })
    @RouteConfig(RouteDefinitions)
    export class AppComponent { }
    

    【讨论】:

    • 嗨 Fateh,感谢您的回复,我是 Angular 的新手,我还没有遇到 @RouteConfig 的概念,我只是想解释一下我正在尝试做的事情我在想同样的事情是否正确。我肯定会尝试您的解决方案,但我的问题是我已将其声明为 loadChildren 是加载其他模块组件的原因
    猜你喜欢
    • 2017-12-22
    • 2020-10-16
    • 1970-01-01
    • 2020-01-24
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多