我正在尝试通过传递URL获得Route对象。
interface Route {
path?: string;
pathMatch?: string;
matcher?: UrlMatcher;
component?: Type<any>;
redirectTo?: string;
outlet?: string;
canActivate?: any[];
canActivateChild?: any[];
canDeactivate?: any[];
canLoad?: any[];
data?: Data;
resolve?: ResolveData;
children?: Routes;
loadChildren?: LoadChildren;
runGuardsAndResolvers?: RunGuardsAndResolvers;
}
在我的导航组件中,我希望通过传递URL来访问Route信息,因为route对象的data属性包含我的Access角色。我知道我可以将此访问角色信息提取到地图上,并在Routes对象和Navigation对象之间共享密钥。但是我希望找到某种原因来遍历Routes对象并从那里提取我的访问信息。
这是我的导航对象的外观:
{ path: '/maintenance/countries', name: 'Countries' }
因此,其中的路径将传递到我的模板中的routerLink中。因此,我正在寻找的是一种使用相同路径来获取数据的方法,该路径是在该对象的Routes对象中设置的。由于存在嵌套路径,我不能仅对Routes对象执行标准过滤器,因此我怀疑我需要某种方式来使用Angular的UrlMatcher。
最后,是我所寻找的虚构示例:
const foundRoute: Route = this.router.findRoute('/maintenance/countries');
const hasAccess = this.authService.hasAccess(foundRoute.data.roles());
在路由器中,您可以像这样传递数据