1. ng g module module/about //创建模块about.module.ts
  2. ng g component module/about //在module中创建组件,自动注册在about.module.ts中
  3. ng g component module/about/components/file //自动注册在about.module.ts中

一、配置一个路由模块

  1. ng g module views/home --routing
  2. ng g component views/home //配置主组件

二、配置模块中的路由

//home-routing.module.ts

  1. import { HomeComponent } from './home.component';
  2. const routes: Routes = [
  3. {
  4. path:"",
  5. component:HomeComponent
  6. }
  7. ]

三、配置主路由

  1. const routes: Routes = [
  2. {
  3. path:"home",
  4. loadChildren:()=>import('./views/home/home.module').then(m=>m.HomeModule)
  5. }
  6. ];