Skip to content

Commit

Permalink
Only search dom for closest A once
Browse files Browse the repository at this point in the history
  • Loading branch information
daankauwenberg committed Oct 11, 2018
1 parent fd18755 commit 35b9f0b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/theme/scripts/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class Router {
}

async _onLinkClick(event) {
// See if what is clicked has an anchor as parent or is a link itself and create an URL of it
const link = event.target.closest('a') ? new URL(event.target.closest('a').href) : null;
if (!link) return;
// See if what is clicked has an anchor as parent or is a link itself. If so create URL otherwise return.
const linkElement = event.target.closest('a');
if (!linkElement) return;
const link = new URL(linkElement.href);

// If it’s an external link, just navigate.
if(link.host !== this._hostname) {
Expand Down

0 comments on commit 35b9f0b

Please sign in to comment.