Open brandon-marginalunit opened 4 years ago
Workaround for anyone else who's stuck on this bug, pushing the navigation instruction onto the event loop seems to work:
/**
* Apply one or more route params, keeping the current route
* and all other param values.
*/
export function assignRouteParams(router: Router, params: {[key: string]: any}) {
if (router.currentInstruction != null) {
setTimeout(() =>
router.navigateToRoute(
router.currentInstruction.config.name ?? "unknown",
{ ...router.currentInstruction.params, ...router.currentInstruction.queryParams, ...params },
{ replace: true }
), 0);
}
}
At the time of this
console.log()
, the actual URL in the browser has been visibly updated. And the parameter does make it intocurrentInstruction
eventually. But for some reason,router.currentInstruction
does not get updated synchronously. This is causing havoc in my logic when I want to do non-destructive changes like the following:Here,
currentInstruction.queryParams
cannot be relied upon to include any changes that have just been made to the params vianavigateToRoute
, which means things get lost.Is this a bug? And if not, is there a workaround? I tried adding
trigger: true
to the options, to no effect.