-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
onEnter called on query changes #2332
Comments
ideally we want both I think, @arnif can you submit the PR with a failing test? |
@knowbody Really? I thought it was intentional that e.g. in going from |
hmmm... why not? |
It just seems weird in that case to run the This wouldn't e.g. be a good fit if we were using patterns like confirming navigation, since you're not actually leaving the Also I assumed it was intentional because otherwise why even bother computing changed routes? It'd be easier to just run |
you are right |
I think that would be the cleanest thing to do, but I'm just trying to infer @mjackson's intentions from the code. I don't know what the actual intended design is. |
I think the problem is something like - we can't map query fields to specific routes the way we can URL parameters. It has to be all or none. |
@mjackson Any thoughts on what should happen in this case? |
This should defintely be reverted, changing query param does not indicate entering a new "page" and it has undesired behavior such as scroll to the top of the page on query param change |
Scrolling to top is expected as default behavior I think - if you had a normal link to the same page with different query parameters, it's the behavior you'd get. |
@refast brings up a good suggestion at #2137 (comment) for adding some sort of |
I'm kinda surprised that If we do need to fire something in response to changing params/query I think having a separate |
@taurose You mean even for the case where you go from e.g. |
Yeah, it's certainly reasonable. I thought it used to be different, but looks like I was wrong anyway :) |
Couldn't those routes be configured something like this: <Route path="widgets" component={ManyWidgets} onEnter={::this.enterManyWidgets}>
<Route path=":id" component={SingleWidget} onEnter={::this.enterSingleWidget}/>
</Route> Where going from |
Yup, so assuming your routes are: <Route path="widgets" component={WidgetParent}>
<Route path=":id" component={WidgetChild} />
</Route> There are two transition categories that are relevant -
Bonus:
In each case, what hooks do we run on |
That's a separate question. New lifecycle hooks should be post-1.0. Why don't we just roll back #2137 (but keep the test cases) for 1.0.0? |
Agreed. Let's roll back #2137. My bad :( |
Ah crud I didn't see that you self-assigned that. Oh well. |
Another solution is an ability to manually reload a route/state. Something like: this.history.pushState(null, '/url/to/current/route', newQueryParams).reload(); Then If you want to reload route after query params changed, you have to do it manually. |
my bad on #2137. I had been using I'm in agreement that "onEnter" should not be called when query params change, however it would be nice if react-router offered a hook for this–something like the |
I'm trying to upgrade from previous versions to the current 1.0(.0-rc4) and got a bit confused as to whether this was fixed or not. It doesn't seem to work for me (onEnter not called when only the query changes). If not fixed intentionally - what's the suggested workaround? In my case the query includes a page number (among others), and the page transition is used to trigger the loading of the required data according to that page number. So I need it to be called e.g. when the user clicks to get the next page... Thanks |
You should not be using |
Sorry for not providing enough details - I'm using flux and am not using the route transition for data loading, but rather just to asynchronically trigger the loading of the required data. No blocking takes place. I guess I'll need to change how I trigger that... |
We discussed this a bit on #rackt on Reactiflux. You'll probably be happier to use e.g. |
Guys, is there any good SO questions on the issue? I've made one, because can't see any solutions around. BTW, http://stackoverflow.com/questions/33671515/firing-callback-on-query-change-in-react-router |
Let's continue discussion on #2547. |
These are my routes:
And in my app I have
<Link to={
${username}/photos} query={{p: photo.id}}>Photos</Link>
Whenever I click that link the
onEnter
function is called.But navigating from
/photos
to/statistics
does not call onEnter (which is expected since i'm not leaving theUserDashboard
component).I found this PR (#2137) and this change causes the problem, reverting fixes it.
The text was updated successfully, but these errors were encountered: