From 0d9c2f26211d34dcafb8afeb3ea06363fe8c2bc5 Mon Sep 17 00:00:00 2001 From: ndungutsecharles103 Date: Wed, 2 Aug 2023 22:31:16 +0200 Subject: [PATCH] fix: fix issue #2 + v1.0.2 --- example/src/components/NavBar.tsx | 4 +++- package.json | 2 +- src/AppProgressBar.tsx | 12 +++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/example/src/components/NavBar.tsx b/example/src/components/NavBar.tsx index e8b83c0..5b0df9f 100644 --- a/example/src/components/NavBar.tsx +++ b/example/src/components/NavBar.tsx @@ -11,7 +11,9 @@ const NavBar = () => { Home About Contact - + + HashLink + HashLink1 ); }; diff --git a/package.json b/package.json index 518cbfc..a9fdf32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next13-progressbar", - "version": "1.0.1", + "version": "1.0.2", "description": "A ProgressBar for next.js 13 with app directory ", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/AppProgressBar.tsx b/src/AppProgressBar.tsx index 556e5c6..7039462 100644 --- a/src/AppProgressBar.tsx +++ b/src/AppProgressBar.tsx @@ -115,11 +115,16 @@ export const Next13ProgressBar = React.memo( // Skip anchors with target="_blank" if (anchorElement.target === '_blank') return; + // Skip anchors with download attribute + if (anchorElement.hasAttribute('download')) return; + + // target url without hash removed const targetUrl = new URL(anchorElement.href); const currentUrl = new URL(location.href); + const isSameUrl = targetUrl?.pathname === currentUrl?.pathname; - if (showOnShallow && targetUrl?.href === currentUrl?.href) return; - if (targetUrl?.href === currentUrl?.href) return; + if (showOnShallow && isSameUrl) return; + if (isSameUrl) return; startProgress(); }; @@ -152,7 +157,8 @@ export function useRouter() { const pathname = usePathname(); function push(href: string, options?: NavigateOptions) { - if (href === pathname) return Promise.resolve(true); + const targetUrl = new URL(href, location.href); + if (targetUrl.pathname === pathname) return Promise.resolve(true); NProgress.start(); return router.push(href, options); }