I found a very neat solution on another stackoverflow post by Thierry Templier, however it is out dated for Angular 2 RC5 new router.
Basically this is the secure directive:
@Directive({
selector: '[secured]'
})
export class SecuredDirective implements OnInit {
@HostBinding('hidden') hideRouterLink: boolean = false;
@Input() routerLink: string;
constructor(private router: Router ) {
console.log(router);
}
ngOnInit(): void {
console.log(this.routerLink);
// How to get routeData here??
// Auth logic
this.hideRouterLink = true;
}
}
Previously on angular's old router we could do this:
var instruction = this.router.generate(this.routeParams);
var data = instruction.component.routeData.data;
Now with RC5, I can't figure out a way how to get the router instruction. Is there another way to do this?
Edit: more info
What I am trying to achieve is to grab the route data defined in the routing.ts example:
{ path: 'control-panel', component: ControlPanelComponent, data: { 'resources': 'controlpanel', 'privileges': 'admin'} }
Any help is greatly appreciated, thanks!