我想在定義路由時添加一些自定義數據以進行路由。如何將自定義數據添加到路線?
我該怎麼做?
喜歡:
{
path: 'department',
component: DepartmentComponent,
customdata: {
name: 'foo',
age: '23'
}
}
我不想在URL中的自定義數據顯示。我只是在內部使用它。
我想在定義路由時添加一些自定義數據以進行路由。如何將自定義數據添加到路線?
我該怎麼做?
喜歡:
{
path: 'department',
component: DepartmentComponent,
customdata: {
name: 'foo',
age: '23'
}
}
我不想在URL中的自定義數據顯示。我只是在內部使用它。
我:
class ConversationCmp {
constructor(r: ActivateRoute) {
r.data.subscribe((p) => {
console.log(p);
});
}
}
這是Route
接口上定義按照以下方式進行:
{ path: 'admin', canActivate: [RoleGuard], data: { roles: ['admin'] } }
我使用它將角色自定義屬性添加到路由中,以便只能訪問具有特定角色的用戶,即我在路由中設置的用戶。
[Angular 2:將數據傳遞給路由?](https://stackoverflow.com/questions/37157838/angular-2-passing-data-to-routes) –