New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export getCurrentLocation
#143
Comments
Why not just save down the One more note on that code, incidentally - due to remix-run/react-router#2502, your history listener actually doesn't necessarily fire in sync with the router update. When using async routes/components, you could potentially update your location significantly before the router update. I've seen this on other similar React Router + Flux integrations, and I'm not sure whether it's correct. |
I don't like for code to depend on external variables, that could potentially get out of sync. I guess saving the location object could work, but I like the beauty of each listener being completely isolated. And this seems like a pretty natural API. Why not make the state observable? Thanks for the note about async routes. I'll have to look into those more. I probably will when I start adding tests and more examples. I have no idea when |
I don't think that's the right thing to do. For example, look at the impl here: https://github.com/rackt/history/blob/v1.13.1/modules/createBrowserHistory.js#L27-L45. Especially if you want to key off router state rather than history state, and to avoid issues when we're using transition hooks or whatever, you're going to end up with something much more robust if you use the location you're given in the listener, rather than trying to figure it out from This is exactly the approach |
Trying to figure it out from I'm fine doing it that way I guess. I just thought the code before had some beauty in it. |
One reason not to expose I'm using just this pattern in scroll-behavior, and so far it's not really bothering me: https://github.com/rackt/scroll-behavior/blob/9479062458e56f7152126ea8ba6e06a788155bd7/modules/utils/createUseScroll.js |
Alright, sounds good. Doesn't bother me too much. It seemed like that |
It largely is, but I think the base |
There is a
getCurrentLocation
that the history object uses internally. Any chance we could export that so we can callhistory.getCurrentLocation()
?I was relying on
window.location
(I love the idea that you are creating compatible location objects) in redux-simple-router, but this breaks when using hash history. The URL that history sees is/foo
, but window.location will report/#/foo?_k=blargh
. See reactjs/react-router-redux#12 for the fun that ensues. (I ping Ryan and Michael in there but we can talk about it here)I need to get the current location to compare it with the URL in the redux store to see if it has changed and we need to update the store. This allows the user to change the URL in the store and then we'll automatically trigger a history update. I suppose we could hack around this and somehow keep a "dirty" flag but this seems more elegant.
The text was updated successfully, but these errors were encountered: