I have a task to implement opening a url in a different tab when clicking on an item in a dropdown menu using Angular 4.4.6 I have a hack solution using a dummy component with a window.open() method to get the job done. But I tend to think there is a more elegant solution to this. Tried a hack using a derivative of this answer, which I believe is close, but I'm missing something. Here is a snippet of what I am trying:
app.module.ts provider excerpt of Resolver
{
provide: 'urlRedirectResolver', useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
//Something like this
window.open((route.data as any).otherUrl);
//OR
window.location.href = window.open((route.data as any).otherUrl);
}
}
app.router.ts route excerpt of Implementation
path: 'SomeComponentURL', component: SomeComponent, resolve: {
url: 'urlRedirectResolver'
},
data: {
otherUrl: (document.location.hash != '#/SomeComponent')
? 'someContent.pdf' : history.back()
}
If the question is too vague please let me know and I'll try to revise it. Any help is greatly appreciated!