Skip to content

Commit

Permalink
Merge pull request #6 from gwendall/master
Browse files Browse the repository at this point in the history
Prevent trigger on open link to another tab
  • Loading branch information
TheSGJ authored Mar 16, 2023
2 parents d2a5505 + 9531b9e commit 857b3ed
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +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 = (event.currentTarget as HTMLAnchorElement).target === "_blank";
function isAnchorOfCurrentUrl(currentUrl: string, newUrl: string) {
const currentUrlObj = new URL(currentUrl);
const newUrlObj = new URL(newUrl);
Expand All @@ -121,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) {
Expand Down

0 comments on commit 857b3ed

Please sign in to comment.