Skip to content

Commit 7be7fbe

Browse files
authored
impr(nav): avoid duplicate browser history entries when re-clicking same nav button (@byseif21) (monkeytypegame#6624)
### Description Closes monkeytypegame#6623
1 parent 61766d3 commit 7be7fbe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

frontend/src/ts/controllers/route-controller.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,18 @@ export function navigate(
159159
}
160160
url = url.replace(/\/$/, "");
161161
if (url === "") url = "/";
162-
history.pushState(null, "", url);
162+
163+
// only push to history if we're navigating to a different URL
164+
const currentUrl = new URL(window.location.href);
165+
const targetUrl = new URL(url, window.location.origin);
166+
167+
if (
168+
currentUrl.pathname + currentUrl.search + currentUrl.hash !==
169+
targetUrl.pathname + targetUrl.search + targetUrl.hash
170+
) {
171+
history.pushState(null, "", url);
172+
}
173+
163174
void router(options);
164175
}
165176

0 commit comments

Comments
 (0)