-
Notifications
You must be signed in to change notification settings - Fork 958
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
Same URL different state not pushed (only replaced) #178
Comments
Yes, correct. I created a sample PR #179 that fixes my problem by comparing states also. |
I'm not sure you always want it to behave like that though. How about adding something like |
@taurose To my mind, |
For clarity, I use history.push() when I want to PUSH, and history.replace() when I want to REPLACE. Why does transitionTo(), which handles both cases internally, change a PUSH to same URL as REPLACE, in the first place? |
@Macroz It's because browsers don't create multiple history entries when clicking a link multiple times on a static website either. On top of that, we can't push the same URL twice for hash history unless they're decorated with a unique query key. I agree it's a bit confusing though now that the public API uses the word @taion I'd say generally it's about passing any data to the next page that you don't want to be contained within the path/URL. Another example could be referral information. The way you describe POST requests sounds like you'd need to do |
@taurose Thanks for the clarification! I feel like the browser behavior is sane for static sites, but now we're talking about a programmatic API to history. I don't see why the programmer can't decide here, which part of the state is in the bookmarkable URL and which part is in the state object. It's the age of the SPA, right? The programmer defines how that action is implemented with regard to the browser history. Sounds like if the state is different, the query key should not be the same either? |
Yes, when using state there should always be a query key. But when not using state/query key (which looks like it may be the default soon), pushing the current URL will be a no-op. So the back button as well as links to the current page would behave differently depending on whether you use hash or browser history, which is something we should try to avoid imo.
Yeah, I want you to be able to decide what's best for yourself, which is why I proposed a more flexible
I agree, but I think generally we should also consider the end users which are accustomed to the way static websites work and provide that behavior as a reasonable default. Same reason we're also trying so hard to provide bookmarkable URLs and support the browser back button. I guess there's an argument to be made that that should be the responsibility of the router and not the history abstraction though. So I'd also be okay with reverting the PR and baking this into the router somehow. But then we'd have to find a solution for #163 that doesn't run into https://github.com/rackt/history/blob/master/modules/createHashHistory.js#L114 . I just don't see much benefit in the approach of #179. I fear that by doing that we'd just be shifting the problem. E.g. to guarantee a PUSH you'd have to add a random id to the state; to get the current behavior, you'd now have to inspect the current location and then call |
That we have it in @taurose If you care about the referrer, doesn't that imply that you want something like a |
I was referring to the 0.x router.transitionTo(..).
Not necessarily I think. I'd tend towards pushing if the page looked vastly different like in the pinterest example. If the difference was minor or even unnoticable (eg. when using referral data for analytics) I'd prefer to use REPLACE. Just to be clear, you'd prefer |
While there is a discussion / problem in the rackt/history about pushing the same URL but different state. See issue remix-run/history#178
Don't we have |
@hannesj Are you suggesting that we move this upstream into |
@taion, that sounds a sensible approach to me. |
@taurose What do you think? |
I agree that the router appears to be a better place for it. I'm not sure about putting it into |
Tricky there - I don't think we want to make |
Yeah, I don't like changing the Another idea would be to have something like a |
Pretty much just pull https://github.com/rackt/react-router/blob/v1.0.2/modules/Link.js#L42 into a function. For example, I do this right now in React-Router-Bootstrap: https://github.com/react-bootstrap/react-router-bootstrap/blob/v0.19.3/src/LinkContainer.js#L23. |
Well, I guess that could help rebuilding |
Well, maybe something like you had above... |
Bump, any update on this? |
No. If you want to move this forward, I'd submit a PR. |
I think #179 is on the right track. Let's follow up there. |
Hi!
I have popup-like components (i.e. tabs, off-canvas). I don't want them to show in the URL or as hashes, as I consider them to be transient state with regards to linkable "friendly" URLs. So I tried to use history PUSH with the same URL, but with a state where the popup is open or not. The problem is that since the URL is the same, I always get a REPLACE and never a PUSH.
This seems to be a feature of PR #43 I also noticed that you have already started fixing the consequences of it, such as issue #166
What do you think about my case? Why should you not be able to push only state changes? Could you comment this? I also don't quite understand the comment in code "treat PUSH to current path like REPLACE to be consistent with browsers".
Thanks!
The text was updated successfully, but these errors were encountered: