From 274aa0242a2a9b73aeaf45121e31a69c651106fe Mon Sep 17 00:00:00 2001 From: Sahiba Mittal Date: Thu, 10 Oct 2024 15:08:23 +0100 Subject: [PATCH] Fix links with href="#" being pushed to Vue router Co-Authored-By: Niklas --- src/App.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/App.vue b/src/App.vue index 02ce9bec..bdd38a59 100644 --- a/src/App.vue +++ b/src/App.vue @@ -125,6 +125,14 @@ export default { const linkTarget = target.getAttribute('target'); if (/\b_blank\b/i.test(linkTarget)) return; } + // don't handle if `href="#"` + if (target && target.getAttribute) { + const linkHref = target.getAttribute('href'); + if ('#' === linkHref) { + event.preventDefault(); + return; + } + } // don't handle same page links/anchors const url = new URL(target.href); const to = url.pathname;