一、配置路由
{
path:"detail/:id",
component:DetailComponent
}
二、参数传递
方法1
//home.html
<a [routerLink]="['/detail',id]" >跳转detail</a>
方法2
<a routerLink="/detail/{{id}}" >跳转detail</a>
三、参数接收
与接收路由类似 这里将this.route.queryParams变成this.route.params
import {ActivatedRoute} from '@angular/router'
...
export class DetailComponent implements OnInit {
constructor(public route:ActivatedRoute) { }
ngOnInit() {
this.route.params.subscribe(res=>{
console.log(res)
})
}
}