Is there a way to extract Route object by passing a URL?
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;
}
In my navigation component, I am looking for a way to access the Route information based on a given URL. The Route object's data property contains Access roles that I need. Rather than extracting this information and sharing keys between Routes object and Navigation object, I am exploring options to traverse the Routes object directly.
This is an example of my Navigation object:
{ path: '/maintenance/countries', name: 'Countries' }
The path in the above object is used in a routerLink in the Template. I am seeking a method to leverage this path to retrieve data stored in the Routes object corresponding to that path. Since the Routes object has nested paths, a standard filter wouldn't suffice, leading me to consider utilizing Angular's UrlMatcher.
To summarize, here is a hypothetical scenario of what I aim to achieve:
const foundRoute: Route = this.router.findRoute('/maintenance/countries');
const hasAccess = this.authService.hasAccess(foundRoute.data.roles());