Skip to content

Commit

Permalink
Merge pull request #99 from AliMD/fix/router
Browse files Browse the repository at this point in the history
Fix router tigger-click bug
  • Loading branch information
alimd authored Mar 12, 2022
2 parents 0dc2b67 + 7917f30 commit ca03444
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions package/router/src/trigger-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,19 @@ export const clickTrigger = {
}

// find the <a> element that the click is at (or within)
let anchor = event
const anchor = event
.composedPath()
.filter(
(eventTarget) => (eventTarget as HTMLElement).tagName.toLowerCase() === 'a',
)[0] as HTMLAnchorElement | null;

while (anchor != null && anchor.tagName.toLowerCase() !== 'a') {
anchor = anchor.parentNode as HTMLAnchorElement | null;
}
.find(
(target) => (target as HTMLElement)?.tagName?.toLowerCase() === 'a',
) as HTMLAnchorElement | undefined;

if (
// ignore if the anchor is not found.
anchor == null ||
// ignore if the anchor is not an <a> element.
anchor.tagName.toLowerCase() !== 'a' ||
anchor.tagName?.toLowerCase() !== 'a' ||
// ignore if the <a> element has a non-default target.
(anchor.target !== '' && anchor.target.toLowerCase() !== '_self' ) ||
(anchor.target !== '' && anchor.target?.toLowerCase() !== '_self' ) ||
// ignore if the <a> element has a download attribute.
anchor.hasAttribute('download') ||
// ignore if the <a> element has a rel attribute.
Expand Down

0 comments on commit ca03444

Please sign in to comment.