Skip to content

Instantly share code, notes, and snippets.

@adrianfaciu
Created February 12, 2018 18:59
Show Gist options
  • Save adrianfaciu/f500be501d53e27a7df0534dd36e5929 to your computer and use it in GitHub Desktop.
Save adrianfaciu/f500be501d53e27a7df0534dd36e5929 to your computer and use it in GitHub Desktop.
import { Directive, HostListener, ElementRef } from '@angular/core';
import { Router } from '@angular/router';
import { isNil } from 'ramda';
@Directive({
selector: 'a[appExternalUrl]',
})
export class ExternalUrlDirective {
constructor(private el: ElementRef, private router: Router) {}
@HostListener('click', ['$event'])
clicked(event: Event) {
const url = this.el.nativeElement.href;
if (isNil(url)) {
return;
}
this.router.navigate(['/externalRedirect', { externalUrl: url }], {
skipLocationChange: true,
});
event.preventDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment