Skip to content

Commit

Permalink
fix: check if url is not the same as current prior to applying locati…
Browse files Browse the repository at this point in the history
…on.href
  • Loading branch information
frankpagan committed Apr 29, 2024
1 parent a0bfb7c commit ca77556
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,14 @@ function run(link) {
if (typeof CoCreate.link !== 'undefined') {
CoCreate.link.open(link)
} else if (link.hasAttribute('href')) {
window.location.href = link.getAttribute('href');
let href = link.getAttribute('href') || '';
// Normalize both URLs to compare paths in a uniform way
const currentPath = new URL(location.href).pathname.replace('/index.html', '/');
const targetPath = new URL(href, location.href).pathname.replace('/index.html', '/');

if (currentPath !== targetPath) {
location.href = href;
}
}
}

Expand Down

0 comments on commit ca77556

Please sign in to comment.