一、配置路由

  1. {
  2. path:"detail/:id",
  3. component:DetailComponent
  4. }

二、参数传递

方法1

  1. //home.html
  2. <a [routerLink]="['/detail',id]" >跳转detail</a>

方法2

  1. <a routerLink="/detail/{{id}}" >跳转detail</a>

三、参数接收

与接收路由类似 这里将this.route.queryParams变成this.route.params

  1. import {ActivatedRoute} from '@angular/router'
  2. ...
  3. export class DetailComponent implements OnInit {
  4. constructor(public route:ActivatedRoute) { }
  5. ngOnInit() {
  6. this.route.params.subscribe(res=>{
  7. console.log(res)
  8. })
  9. }
  10. }