history
history copied to clipboard
history.block missing documentation regarding returning booleans
Hi,
I'm migrating from react-router
v3 to v5 and coincidentally from history
v3 to v4. I've noticed that the new history.block
method is missing the documentation piece about returning a simple boolean to block navigation (and not open a browser prompt). I've been using that in v3 with listenBefore
to show a custom UI modal instead of the default browser prompt. I had to look through the source code to find out that this was still supported. I still couldn't find a way to do that asynchronously without rejecting everything and then replaying location objects if the transition is confirmed.
I guess it would be great to specify that in the Readme.md.
Additionally I would like to mention that getUserConfirmation
is often impossible to use, as one would like to have access to the React rendering context to render custom UI, which is often unavailable at the time of setting history up. This is what pushed me towards looking though source to get back the previous functionality.
P.S. If you go ahead with removing history.block
entirely, please allow for an easy way to work around that with a custom plugin. However flawed it may be, for many people it fits their use case perfectly. And thank you for maintaining the library. I enjoyed using it without issues for a long time.
P.P.S. I ended up monkey patching the history instance so: https://github.com/goodhood-eu/history-block-async/blob/master/src/index.es
There is also an issue with return type of TransitionPromptHook
. Possible return values don't include true
which is incorrect.