Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui-router does not run a parent state's resolve promise when using $state.go()

I have an abstract parent state with a resolve promise which returns information about the current user. This information is injected into controllers of all the child states.

However when I use $state.go('parent.child') the resolve promise function is not being executed. If I browse to the URL representing that state though, it executes fine.

Do I need to specify the resolve object on each child state and omit it from the parent?

like image 410
n4cer500 Avatar asked Jan 11 '23 00:01

n4cer500


1 Answers

A parent state resolve will only resolve once for a given set of $stateParams values. If the parent state does not rely on $stateParams or does not use any, then its dependencies will only be resolved once, regardless of any child state changes.

The difference in behaviour you are seeing is a child state change will not result in the parent resources being reloaded, whereas the location change will as the full parent and child states are reloaded.

You can observe this behaviour in this plunk.

The example has a $stateParams value in the parent state on which the children are dependent. Changing state via $state.go or ui-sref (both methods are provided) will result in a refresh of the parent resource. However, changing state to a child state without a change to the $stateParams parameter will not refresh the parent resource and the previously returned value will be provided.

like image 91
do0g Avatar answered Apr 19 '23 11:04

do0g