gpt4 book ai didi

angular - 如何以 Angular 2获取当前路线自定义数据?

转载 作者:太空狗 更新时间:2023-10-29 16:51:41 24 4
gpt4 key购买 nike

我已经设置了如下路线

const appRoutes: Routes = [
{
path: 'login',
component: LoginComponent,
data: {
title: 'Login'
}
},
{
path: 'list',
component: ListingComponent,
data: {
title: 'Home Page',
module:'list'
}
},
{
path: '',
redirectTo: '/login',
pathMatch: 'full'
},
];

现在当我到达'/list' 路线然后在'listing.component.ts' 我写了下面的代码

export class ListingComponent {

public constructor(private router:Router) {
//here how i can get **data** of **list** routes

}
}

最佳答案

public constructor(private route:ActivatedRoute, private router:Router) {
console.log(route.snapshot.data['title'])
}

关于angular - 如何以 Angular 2获取当前路线自定义数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40863664/

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