From ca7755649cc769983932247e0821143b03d8f740 Mon Sep 17 00:00:00 2001 From: frankpagan Date: Mon, 29 Apr 2024 00:08:41 -0500 Subject: [PATCH] fix: check if url is not the same as current prior to applying location.href --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 65ab425..c560b05 100644 --- a/src/index.js +++ b/src/index.js @@ -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; + } } }