我试图在角度2路由器测试版中传递多个参数。但是得到了错误。
我的app.route.ts文件
export const routes : RouterConfig =[
{path:'',component:DashboardComponent},
{path:'login',component:LoginComponent},
{path:'signup',component:SignupComponent},
{path:'profile/:type/:name',component:ProfileComponent}
];
export const APP_ROUTER_PROViDERS = [
provideRouter(routes)
];
dashboard.component.ts
export class DashboardComponent{
constructor(private router:Router){
}
profile():void{
this.router.navigate(['/profile',{type:'artist',name:'mash'}]);
}}
profile.component.ts
export class ProfileComponent implements OnInit{
constructor(private route:ActivatedRoute,private router:Router){
}
type:string;
name:string;
ngOnInit(){
console.log(this.route.snapshot.params);
}}
我现在该怎么办?请帮忙。提前谢谢。
答案 0 :(得分:2)
对于路线参数,只需使用
this.router.navigate(['/profile','artist','mash']);
您添加的数组用于查询参数。