Skip to content

Commit

Permalink
fix(demo): Fixed routings issue for links with inner html tags (#3816)
Browse files Browse the repository at this point in the history
Closes #3813
  • Loading branch information
svetoldo4444ka authored and valorkin committed Mar 1, 2018
1 parent e748105 commit 5869afb
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ export class ExamplesComponent {
}

@HostListener('document:click', ['$event'])
preventEmptyHrefNav(event: Event) {
if (event && event.target && (event.target as Element).getAttribute('href') === '#') {
preventEmptyHrefNav(event: MouseEvent & {target: Element}): void {
let element: Element = event.target;
let preventNav = element.getAttribute('href') === '#';

if (preventNav) {
event.preventDefault();
return;
}

if (element.tagName !== 'A') {
while (element !== document.body) {
if (preventNav) {
event.preventDefault();
return;
}
element = element.parentElement;
preventNav = element.getAttribute('href') === '#';
}
}
}
}

0 comments on commit 5869afb

Please sign in to comment.