gpt4 book ai didi

javascript - 如何处理 Angular 2 路由器测试版中的多个参数?

转载 作者:太空狗 更新时间:2023-10-29 18:33:42 25 4
gpt4 key购买 nike

我正在尝试在 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

我现在应该尝试什么?请帮忙。提前致谢。

最佳答案

对于路由参数,只需使用

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

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

关于javascript - 如何处理 Angular 2 路由器测试版中的多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38430492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com