• this.router.navigate

    1.动态路由的事件跳转

  1. <button (click)="handleClick()">跳转detail</button>
  1. //导入路由
  2. import {Router} from "@angular/router"
  3. export class HomeComponent implements OnInit {
  4. public id:string = "1213"
  5. //配置
  6. constructor(private router:Router) { }
  7. handleClick(){
  8. //跳转
  9. this.router.navigate(['/detail',this.id])
  10. }
  11. }

2.get传值的事件跳转

  • 导入NavigationExtras
    1. import {Router,NavigationExtras} from "@angular/router"
  1. //配置 NavigationExtras的参数
  2. export class HomeComponent implements OnInit {
  3. public id:string = "1213"
  4. constructor(private router:Router) { }
  5. handleClick(){
  6. let navigationExtras:NavigationExtras ={
  7. queryParams:{
  8. "id":this.id
  9. }
  10. }
  11. //跳转
  12. this.router.navigate(['/detail'],navigationExtras)
  13. }
  14. }