Skip to content

Commit 35b9f0b

Browse files
Only search dom for closest A once
1 parent fd18755 commit 35b9f0b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/theme/scripts/router.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ class Router {
3434
}
3535

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

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

0 commit comments

Comments
 (0)