From 3f40893328d181ce647a4fa5a6b3804d7d3ddcfe Mon Sep 17 00:00:00 2001 From: joetis06 <58756900+joetis06@users.noreply.github.com> Date: Fri, 13 Oct 2023 21:02:41 -0400 Subject: [PATCH] Update atomWithHash replaceState function to use window.history.state instead of null My project uses the new NextJS app router, and we were using atomWithHash to keep track of state. This was breaking when used with the app router when using the back button in the browser. In my project I am just setting the setHash function to do what I committed here. I figured it would be better and easier for anyone else using this library to just set the flag replaceState if they are using the nextjs app router. (Maybe the website/documentation should be updated as well.) --- src/atomWithHash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atomWithHash.ts b/src/atomWithHash.ts index 6081098..9a8058f 100644 --- a/src/atomWithHash.ts +++ b/src/atomWithHash.ts @@ -34,7 +34,7 @@ export function atomWithHash( if (setHashOption === 'replaceState') { setHash = (searchParams) => { window.history.replaceState( - null, + window.history.state, '', `${window.location.pathname}${window.location.search}#${searchParams}`, );