Skip to content

Commit ccbe09d

Browse files
committed
prevent duplicate history push when clicking on the same link twice
1 parent e8ea27a commit ccbe09d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-navigator",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Solid Navigator is a library that is inspired by vue router and solid router.",
55
"license": "MIT",
66
"author": "SupertigerDev",

src/navigator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const createNavigate = (
1818
return (path: string, options?: NavigateOptions) => {
1919
let newPath = path
2020
let currentPathname = pathname()
21+
const currentSearchAndHash = getSearchAndHash()
2122

2223
if (currentPathname.endsWith('/')) {
2324
currentPathname = currentPathname.slice(0, -1)
@@ -31,6 +32,9 @@ export const createNavigate = (
3132
newPath = currentPathname + '/' + newPath
3233
}
3334

35+
const pathAndSearch = currentPathname + currentSearchAndHash
36+
if (pathAndSearch === newPath) return
37+
3438
if (options?.replace) {
3539
history.replaceState(options.state || null, '', newPath)
3640
} else {

0 commit comments

Comments
 (0)