Replies: 1 comment 5 replies
-
I agree. As a workaround, I wrote this helper function which uses the History API directly to replace state. Note, that the state provided by the react-router
|
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As far as I know, currently it's not possible to replace the history state without redirection. It's a bit surprising, given it's super useful to put data to be remembered on the current page in case user navigates away and then comes back. Even the native
history.replaceState()
puts thestate
param first in order to allow state change without changing the URL. The docs forreact-router
discourage usinghistory.state
directly, while not providing support for its basic features. I'm confused.In my opinion, it should also cause stable behavior, like
useRef()
. It's just a piece of data attached to the current context. If that triggers moreuseEffect()
and re-renders, it would be annoying to work with.The most obvious scenario is remembering scrolling positions of certain scrollable elements (not just the
<body>
), but there are many, many more use cases.Beta Was this translation helpful? Give feedback.
All reactions