history icon indicating copy to clipboard operation
history copied to clipboard

Bring back `location.action`

Open OliverJAsh opened this issue 3 years ago • 1 comments

In v3 we had location.action. Unfortunately it seems like it was removed in v4: https://github.com/ReactTraining/history/commit/c07c611cfcbfce85e055c1c16f22e56744ac9970. I couldn't find any notices about this in various changelogs.

v3:

> require('history').createMemoryHistory().getCurrentLocation().action
'POP'

v4:

> require('history').createMemoryHistory().location.action
undefined

I understand I can use history.action instead, but history is mutated so I don't feel comfortable relying on it, whereas location is not mutated.

My use case: when my component renders, I want to know what the action was so I can decide whether to reset scroll or not. Again, history.action works, but there is no guarantee it will correspond to the location my component is currently rendering with, because history is mutated.

For reference, here is a previous discussion which might be related: https://github.com/ReactTraining/history/issues/449.

I would be happy to send a PR to bring this back if you agree. What do you think?

OliverJAsh avatar Mar 19 '21 09:03 OliverJAsh

:wave: Hi, is there any eta for this feature? Our scroll restoration implementation heavily depends on it. Currently, we expose the whole history instance by implementing a custom router component, but it seems a bit tricky. We may move to use the UNSAFE_NavigationContext introduced by the recent beta version, but it is still not ideal. We do think this is a critical feature and hope it could be landed soon. Thanks.

latin-1 avatar Sep 25 '21 09:09 latin-1