pmndrs / jotai

👻 Primitive and flexible state management for React
https://jotai.org
MIT License
18.67k stars 614 forks source link

[atomWithHash] replaceState should probably keep current path? #1110

Closed pakettiale closed 2 years ago

pakettiale commented 2 years ago

Setting options.replaceState = true causes the atom to overwrite current path with #{jotai_hash}. I would think what it should instead write previous/path#{jotai_hash}. Current implementation does not work well in SPAs that use react-router or similar libraries.

If this is the case I could write a PR to solve this.

dai-shi commented 2 years ago

Yeah, that would be nice. Makes sense. We didn't cover such use cases. Feel free to open a PR. If you have questions, let me know.

jakkku commented 2 years ago

hi! i want to work on this issue, but it seems to work well.
https://codesandbox.io/s/react-typescript-forked-oe0v11?file=/src/App.tsx

am i missing something?

dai-shi commented 2 years ago

Hmm, I'm actually not very sure about the issue. @pakettiale Are you still around?

pakettiale commented 2 years ago

Hmm that codesandbox works for me too. Not sure why I then had issues originally. Maybe something else was conflicting :thinking:

But I think this issue can then be considered solved.

jakkku commented 2 years ago

I modified the codesandbox. The problem seems to arise if I navigate to another page after changing the hash.

Can you check again? https://codesandbox.io/s/hcdjnj?file=/src/App.tsx