项目目录

创建模块

  1. ng g module module/user --routing
  2. ng g module module/article --routing
  3. ng g module module/product --routing

创建组件

  1. ng g component module/user
  2. ng g component module/user/components/profile
  3. ng g component module/user/components/order
  4. ng g component module/article
  5. ng g component module/article/components/articlelist
  6. ng g component module/article/components/info
  7. ng g component module/product
  8. ng g component module/product/components/plist
  9. ng g component module/product/components/pinfo

1.app.module.ts

  1. import { BrowserModule } from '@angular/platform-browser';
  2. import { NgModule } from '@angular/core';
  3.  
  4. import { AppRoutingModule } from './app-routing.module';
  5. import { AppComponent } from './app.component';
  6.  
  7. @NgModule({
  8. declarations: [
  9. AppComponent
  10. ],
  11. imports: [
  12. BrowserModule,
  13. AppRoutingModule
  14. ],
  15. providers: [],
  16. bootstrap: [AppComponent]
  17. })
  18. export class AppModule { }

app.component.html

  1. <header>
  2. <a [routerLink]="['/user']">用户模块</a>
  3. <a [routerLink]="['/article']">文章模块</a>
  4. <a [routerLink]="['/product']">商品模块</a>
  5. </header>
  6. <router-outlet></router-outlet>

app-routing.module.ts

  1. import { NgModule } from '@angular/core';
  2. import { Routes, RouterModule } from '@angular/router';
  3.  
  4. const routes: Routes = [
  5. {
  6.  
  7. path:'user',loadChildren:'./module/user/user.module#UserModule'
  8. },
  9. {
  10.  
  11. path:'article',loadChildren:'./module/article/article.module#ArticleModule'
  12. },
  13. {
  14.  
  15. path:'product',loadChildren:'./module/product/product.module#ProductModule'
  16. },
  17.  
  18. {
  19.  
  20. path:'**',redirectTo:'user'
  21. }
  22.  
  23. ];
  24.  
  25. @NgModule({
  26. imports: [RouterModule.forRoot(routes)],
  27. exports: [RouterModule]
  28. })
  29. export class AppRoutingModule { }

用户模块user.module.ts

  1. import { NgModule } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3.  
  4. import { UserRoutingModule } from './user-routing.module';
  5. import { UserComponent } from './user.component';
  6. import { ProfileComponent } from './components/profile/profile.component';
  7. import { AddressComponent } from './components/address/address.component';
  8.  
  9. @NgModule({
  10. declarations: [UserComponent, ProfileComponent, AddressComponent],
  11. imports: [
  12. CommonModule,
  13. UserRoutingModule
  14. ]
  15. })
  16. export class UserModule { }

 user-routing-module.ts

  1. import { NgModule } from '@angular/core';
  2. import { Routes, RouterModule } from '@angular/router';
  3.  
  4. import { UserComponent } from './user.component';
  5.  
  6. import { ProfileComponent } from './components/profile/profile.component';
  7. import { AddressComponent } from './components/address/address.component';
  8.  
  9. const routes: Routes = [
  10. {
  11. path:'',component:UserComponent
  12. },
  13. {
  14. path:'profile',component:ProfileComponent
  15. },
  16. {
  17. path:'address',component:AddressComponent
  18. }
  19. ];
  20.  
  21. @NgModule({
  22. imports: [RouterModule.forChild(routes)],
  23. exports: [RouterModule]
  24. })
  25. export class UserRoutingModule { }

其他模块类似配置

自定义模块的父子路由

  1. import { NgModule } from '@angular/core';
  2. import { Routes, RouterModule } from '@angular/router';
  3.  
  4. import { ProductComponent } from './product.component';
  5.  
  6. import { PlistComponent } from './components/plist/plist.component';
  7. import { CartComponent } from './components/cart/cart.component';
  8. import { PcontentComponent } from './components/pcontent/pcontent.component';
  9.  
  10. const routes: Routes = [
  11.  
  12. {
  13.  
  14. path:'',component:ProductComponent,
  15. children:[
  16. {path:'cart',component:CartComponent},
  17. {path:'pcontent',component:PcontentComponent}
  18. ]
  19.  
  20. },
  21.  
  22. {path:'plist',component:PlistComponent}
  23. ];
  24.  
  25. @NgModule({
  26. imports: [RouterModule.forChild(routes)],
  27. exports: [RouterModule]
  28. })
  29. export class ProductRoutingModule { }

Angular 自定义模块以及配置路由实现模块懒加载的更多相关文章

  1. angular配置懒加载路由的思路

    前言 本人记性不好,对于别人很容易记住的事情,我愣是记不住,所以还是靠烂笔头来帮我长长记性. 参考文章:https://blog.csdn.net/xif3681/article/details/84 ...

  2. Angular性能优化实践——巧用第三方组件和懒加载技术

    应该有很多人都抱怨过 Angular 应用的性能问题.其实,在搭建Angular项目时,通过使用打包.懒加载.变化检测策略和缓存技术,再辅助第三方组件,便可有效提升项目性能. 为了帮助开发者深入理解和 ...

  3. vue-cli 项目实现路由懒加载

    在vue 单页应用中,如果路由不实现懒加载,那么打包出来的文件将会非常大,加载也会非常慢.vue-router 官网也有相应的介绍,但是具体怎么去实现还是讲的比较模糊的,下面将一步步讲解配置路由懒加载 ...

  4. vue路由懒加载

    大项目中,为了提高初始化页面的效率,路由一般使用懒加载模式,一共三种实现方式.(1)第一种写法: component: (resolve) => require(['@/components/O ...

  5. vue2.x 路由懒加载 优化打包体积

    当打包构建应用时,Javascript 包会变得非常大,影响页面加载.如果我们能把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了. 结合 Vue 的异步组 ...

  6. vue+webpack2实现路由的懒加载

    当打包构建应用时,Javascript 包会变得非常大,影响页面加载.如果我们能把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了. 结合 Vue 的异步组 ...

  7. 「Vue.js」Vue-Router + Webpack 路由懒加载实现

    一.前言 当打包构建应用时,Javascript 包会变得非常大,影响页面加载.如果我们能把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了.结合 Vue ...

  8. 路由懒加载---Vue Router

    一.什么是懒加载? 懒加载也就是延迟加载或者按需加载,即在需要的时候进行加载. 二.为什么在Vue路由中使用懒加载? 像vue这种单页面应用,如果没有应用懒加载,运用webpack打包后的文件将会异常 ...

  9. 18-Angular 自定义模块以及配置路由模块懒加载

    新建项目,新建几个子模块,实现懒加载 用户.商品.文章 新建这三个模块 创建模块的时候后面加 --routing.会自动生成模块的路由文件 先删掉. 重新创建模块带routing 这样就会生成两个文件 ...

随机推荐

  1. KVM虚拟机的管理

    1.  查看KVM虚拟机配置文件及运行状态 (1) KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostart目录是配置kvm虚拟机开机自启动目录 (2) virsh命令 ...

  2. Java学习笔记——第2篇

    Java程序的基本规则 Java程序的组织形式:纯粹的面向对象的程序设计语言,所以Java程序必须以类的形式存在,类是Java程序的最小程序单位,Java程序不允许可执行语句.方法等成分独立存在,所有 ...

  3. jsx的本质

    jsx语法 1.所有html标签他都支持        <div></div> 2.大括号里面可以引入js变量 或者 表达式       {name || ''} 3.可以做判 ...

  4. Nginx入门(三)——正向代理

    server { resolver 114.114.114.114; #指定DNS服务器IP地址 listen 443; location / { proxy_pass https://$host$r ...

  5. machine learning(10) -- classification:logistic regression cost function 和 使用 gradient descent to minimize cost function

    logistic regression cost function(single example) 图像分布 logistic regression cost function(m examples) ...

  6. PL/SQL 使用控制流程

    一.条件分支语句 1.if判断 IF <布尔表达式> THEN PL/SQL 和 SQL语句 END IF; 2.if else判断 IF <布尔表达式> THEN PL/SQ ...

  7. Oracle递归查询connect by

    一.概述 Oracle中可以通过START WITH . . . CONNECT BY . . .子句来实现SQL的层次查询. 自从Oracle 9i开始,可以通过 SYS_CONNECT_BY_PA ...

  8. mybatis-generator数据库注释实体类生成以及generatorConfig文件配置

    项目里新建表时model,mapper以及mapper.xml基本都是用Mybatis Generator(以下简称为MBG)自动生成的,但是MBG自动生成的model的注释实在有点非人类,至少中国人 ...

  9. 2019牛客暑期多校训练营(第十场)Coffee Chicken——递归

    题意 $S(1) = "COFFEE", S(2)="CHICKEN"$,$S(n) = S(n-2)+S(n-1)$,请输出 $S(n)$ 中从第 $k$ 个 ...

  10. redis 介绍与操作

    参考连接:  https://www.cnblogs.com/wupeiqi/articles/5132791.html redis 是什么? redis是一个软件,帮助开发者对一台机器的内存进行操作 ...