3-1跳转
首页中跳转 home.component.html
<a [routerLink]="['/detail']" [queryParams]="{id:id}">跳转到detail</a>
id是个变量,要先在home.component.ts中声明
export class HomeComponent implements OnInit {
public id:string="123"
...
}
3-2详情页接收 this.route.queryParams
detail.component.ts
//导入正在显示的路由
import {ActivatedRoute} from '@angular/router'
export class DetailComponent implements OnInit {
//构造函数中配置
constructor(public route:ActivatedRoute) { }
ngOnInit() {
//subscribe触发
this.route.queryParams.subscribe(res=>{
console.log(res)
})
}
}