I have setup my routes and route guards in Angular and they are working great for stopping the user from accessing a route that they shouldn't. However, I have a global navigation section on all my pages and it basically loops over my array of Routes and displays all of the links (using *ngFor). I would like to have each Route evaluated when I'm looping over them to see if the use canActivate that route. This way I am not showing the user a link for something they cannot visit. I'd like to do this in a way that that the same route guard logic is reused.
I have an array of routes like so:
const routes: Routes = [
{
path: 'dashboard-simple',
component: DashboardSimpleComponent,
canActivate: RoleGuard,
data: {roles: ['Basic']}
},
{
path: 'dashboard-advanced',
component: DashboardAdvancedComponent,
canActivate: RoleGuard,
data: {roles: ['Admin']}
},
// And so on...
];
The template looks like this:
<ul>
<li *ngFor="let route of routes"><a [routerLink]="route.path">{{ route.path }}</a></li>
</ul>