Skip to content

Commit 2d4ed85

Browse files
committed
fix: issue #10 + v1.1.2
1 parent 8f68b72 commit 2d4ed85

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

example/src/components/NavBar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const NavBar = () => {
1414
<button onClick={() => router.push('/button-link#34')}>ButtonLink</button>
1515
<Link href={'#'}>HashLink</Link>
1616
<Link href={'/contact/#44'}>HashLink1</Link>
17+
<button onClick={() => router.replace('/about')}>Replace</button>
1718
</div>
1819
);
1920
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next13-progressbar",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "A ProgressBar for next.js >=13 with app directory ",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -54,4 +54,4 @@
5454
"dist/**/*.mjs*",
5555
"dist/**/*.d*"
5656
]
57-
}
57+
}

src/AppProgressBar.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,12 @@ export function useRouter() {
166166
return router.push(href, options);
167167
}
168168

169-
return { ...router, push };
169+
function replace(href: string, options?: NavigateOptions) {
170+
const targetUrl = new URL(href, location.href);
171+
if (targetUrl.pathname === pathname) return Promise.resolve(true);
172+
NProgress.start();
173+
return router.replace(href, options);
174+
}
175+
176+
return { ...router, push, replace };
170177
}

0 commit comments

Comments
 (0)