如何处理angular 2路由器beta中的多个参数?

时间:2016-07-18 07:06:53

标签: javascript typescript angular

我试图在角度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);
}}

错误 enter image description here

我现在该怎么办?请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:2)

对于路线参数,只需使用

this.router.navigate(['/profile','artist','mash']);

您添加的数组用于查询参数。

相关问题