Skip to content

Commit

Permalink
fix: fix issue #2 + v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ndungtse committed Aug 2, 2023
1 parent c957add commit 0d9c2f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion example/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const NavBar = () => {
<Link href={'/'}>Home</Link>
<Link href={'/about'}>About</Link>
<Link href={'/contact'}>Contact</Link>
<button onClick={() => router.push('/button-link')}>ButtonLink</button>
<button onClick={() => router.push('/button-link#34')}>ButtonLink</button>
<Link href={'#'}>HashLink</Link>
<Link href={'/contact/#44'}>HashLink1</Link>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/AppProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0d9c2f2

Please sign in to comment.