1.1 设置路由

  1. //app-routing.module.ts
  2. 1.导入参与路由的组件
  3. import { HomesComponent } from './components/router/homes/homes.component'
  4. import { NewComponent } from './components/router/new/new.component'
  5. import { ProductComponent } from './components/router/product/product.component'
  6. import { LoginComponent } from './components/router/login/login.component'
  7. 2.配置路由
  8. const routes: Routes = [
  9. {
  10. path:'login',
  11. component:LoginComponent
  12. },
  13. {
  14. path: 'home',
  15. component:HomesComponent,
  16. },
  17. {
  18. path:'new',
  19. component:NewComponent
  20. },
  21. {
  22. path:'product',
  23. component:ProductComponent
  24. }
  25. ]

1.2 路由的跳转

<a routerLink="/new">新闻组件</a> -->
//静态路由的跳转



<a [routerLink]="[ '/home' ]" routerLinkActive="active">首页</a>
//动态路由的跳转   routerLinkActive可以设置路由的样式  active为类名
<a [routerLink]="[ '/new' ]" routerLinkActive="active">新闻</a>