As it is also implied by the documentation;
... Note: resources are only refreshed on route change. The router does not poll or update resources in the background. Navigation within the same route, e.g. query param change, will not trigger a refresh of resources.
The resource is not refreshed when the query is changed by;
const [page = '1', setPage] = useQueryParam('page');
// call setPage() somewhere
Only way to force a refetch seems to be via an additional;
const resource = useResource(routeResource);
// resource.refetch() forces a proper update
Then, in resource's getData function the query is not properly updated and only way to practically access it is via window.location, which is an implementation detail and should not be ideally used:
getData: (routerContext) => {
const params = new URLSearchParams(window.location.search);
const page = params.get('page') || '1';
// want to use page here, routerContext.query is a stale value from the previous route change for some reason
}
Ideally I would expect it to get triggered for query param changes as well. As it has probably now became a public behaviour maybe we can do it behind a boolean option?
Even this is not implemented, routerContext should get properly updated before getData is called so that we have a workaround.
As it is also implied by the documentation;
Only way to force a refetch seems to be via an additional;
Then, in resource's
getDatafunction the query is not properly updated and only way to practically access it is viawindow.location, which is an implementation detail and should not be ideally used:Ideally I would expect it to get triggered for query param changes as well. As it has probably now became a public behaviour maybe we can do it behind a boolean option?
Even this is not implemented,
routerContextshould get properly updated beforegetDatais called so that we have a workaround.