From acff0dc376cc0f2a9ffee80e7f1ececb036c08ff Mon Sep 17 00:00:00 2001 From: gwendall Date: Wed, 15 Mar 2023 21:44:25 +0100 Subject: [PATCH 1/3] Prevent trigger on open link to another tab --- src/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index d06e6c9..07bc16c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -101,6 +101,8 @@ const NextTopLoader = (props: NextTopLoaderProps) => { navLink.addEventListener('click', (event: MouseEvent) => { let currentUrl = window.location.href; let newUrl = (event.currentTarget as HTMLAnchorElement).href; + let isExternalLink = Boolean((event.currentTarget as HTMLAnchorElement).target === "_blank"); + if (isExternalLink) return null; function isAnchorOfCurrentUrl(currentUrl: string, newUrl: string) { const currentUrlObj = new URL(currentUrl); const newUrlObj = new URL(newUrl); From 1a7e2362b29bbeba4c06ca6e0dd6e3e78e26b0da Mon Sep 17 00:00:00 2001 From: gwendall Date: Wed, 15 Mar 2023 21:46:06 +0100 Subject: [PATCH 2/3] Update index.tsx --- src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index 07bc16c..07fcfe9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -101,7 +101,7 @@ const NextTopLoader = (props: NextTopLoaderProps) => { navLink.addEventListener('click', (event: MouseEvent) => { let currentUrl = window.location.href; let newUrl = (event.currentTarget as HTMLAnchorElement).href; - let isExternalLink = Boolean((event.currentTarget as HTMLAnchorElement).target === "_blank"); + let isExternalLink = (event.currentTarget as HTMLAnchorElement).target === "_blank"; if (isExternalLink) return null; function isAnchorOfCurrentUrl(currentUrl: string, newUrl: string) { const currentUrlObj = new URL(currentUrl); From 9531b9eb43b3a0e4965acdafd0ead443a82da36c Mon Sep 17 00:00:00 2001 From: Shri Ganesh Jha <60005430+TheSGJ@users.noreply.github.com> Date: Thu, 16 Mar 2023 18:59:10 +0545 Subject: [PATCH 3/3] Update index.tsx --- src/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 07fcfe9..19d0be5 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -102,7 +102,6 @@ const NextTopLoader = (props: NextTopLoaderProps) => { let currentUrl = window.location.href; let newUrl = (event.currentTarget as HTMLAnchorElement).href; let isExternalLink = (event.currentTarget as HTMLAnchorElement).target === "_blank"; - if (isExternalLink) return null; function isAnchorOfCurrentUrl(currentUrl: string, newUrl: string) { const currentUrlObj = new URL(currentUrl); const newUrlObj = new URL(newUrl); @@ -123,7 +122,7 @@ const NextTopLoader = (props: NextTopLoaderProps) => { return false; } const isAnchor = isAnchorOfCurrentUrl(currentUrl, newUrl); - if (newUrl === currentUrl || isAnchor) { + if (newUrl === currentUrl || isAnchor || isExternalLink) { NProgress.start(); NProgress.done(); [].forEach.call(npgclass, function (el: Element) {