Skip to content

Commit

Permalink
Fix links with href="#" being pushed to Vue router
Browse files Browse the repository at this point in the history
Co-Authored-By: Niklas <[email protected]>
  • Loading branch information
sahibamittal and nscuro committed Oct 10, 2024
1 parent 3594c53 commit 274aa02
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 274aa02

Please sign in to comment.