如何以角度 2 获取当前路线自定义数据? [英] How to get current route custom data in angular 2?
本文介绍了如何以角度 2 获取当前路线自定义数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设置的路线如下
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'
我写了下面的代码
now when i come to '/list'
route then on 'listing.component.ts'
i have written below code
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']);
}
这篇关于如何以角度 2 获取当前路线自定义数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文