1. 在路由中配置动态路由
{
path:'newcontent/:aid',
component:LoginComponent
},
2. 传值
//list为一个数组经过for循环后加入小于10的数
<ul>
<li *ngFor="let item of list;let key = index">
<a [routerLink]="[ '/newcontent/', key ]">{{key}} -- {{item}}</a>
</li>
</ul>
3.接收传值
//导入接受传值模块
import { ActivatedRoute } from '@angular/router'
//实例化
export class LoginComponent implements OnInit {
constructor(public route:ActivatedRoute) { }
ngOnInit() {
//接受传值
this.route.params.subscribe(res=>{
console.log(res);
})
}
}