ui-router: Problem with reloadOnSearch: false - change in stateParams doesn't reload
Here is my issue:
I navigate through a list of links, that display different images depending on the date in the search parameters (?from&to).
Those search parameters should not trigger a state reload. Finally, here is my state declaration:
state('links/:linkId', {
url: "/links/linkId?from&to",
reloadOnSearch: false,
templateUrl: ...
Controller: ...
});
But then a huge problem shows up! When I try to navigate through my different links, reload doesn’t happen anymore, so that I cannot pass from one link to another.
After some digging in the code, I found out that when reloadOnSearch
equals to false, triggers are always blocked because there’s absolutely no checking of whether the changing parameters are search parameters or path parameters.
So actually, reloadOnSearch
doesn’t work as intended and should be renamed reloadOnStateParamsChange
.
I fixed the issue by checking if the state parameters that changed are search parameters or not, which seems to work fine.
Please tell me if I’m mistaking somewhere or if it is relevant, and also if you would be interested in a pull request or a plunkr.
Thanks in advance!
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 35 (13 by maintainers)
Commits related to this issue
- fixes #1079 state will now be reloaded if `state.reloadOnSearch = false` when doing `state.go('stateName', {reload: true})` — committed to homerjam/ui-router by homerjam 10 years ago
- fix($state): reloadOnSearch should not affect non-search param changes. The handling of `reloadOnSearch: false` caused ui-router to avoid reloading the state in more cases than it should. The designe... — committed to metamatt/ui-router by deleted user 9 years ago
My hilarious hack for this is as follows
//set the reloadOnSearch on state to false initially in some code block $state.current.reloadOnSearch = false;
// update query string here $location.search({“from”: 1, “to”: 2});
//revert reloadOnSearch on the state! $timeout(function () { $state.current.reloadOnSearch = undefined; });
@TEHEK A workaround is to make your state abstract and define
reloadOnSearch
true (which it is by default) and create a child state that only defines a url with the query string parameters you want to not cause a state reload.E.g.: