From 5869afb2ba0306a68613eb692c25ba2cf41220b0 Mon Sep 17 00:00:00 2001 From: svetoldo4444ka Date: Thu, 1 Mar 2018 16:04:13 +0200 Subject: [PATCH] fix(demo): Fixed routings issue for links with inner html tags (#3816) Closes #3813 --- .../examples.component.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts b/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts index 30365f19ae..e425c98a0d 100644 --- a/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts +++ b/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts @@ -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') === '#'; + } } } } +