Search code examples
angularangular-ui-routertransition

Setting url through `urlService.url` not working inside `onEnter`


One of our requirements is having to redirect to a certain url from within an onEnter hook in one of my states. I have the following code:

image

It seems that is not working properly in most cases (I'm really sorry that I can't replicate what I have in this project in a repro repo):

image

After this final log, the app hangs in that state, and no transitions are made to the url I specify in urlService.url(...) call.

My question is, what is the proper way to redirect to another url (the url of course will be a match in one of my states) inside the onEnter hook. I know that the proper way would have been to return a redirect target, but as I only have a raw url, I have no idea how to do that.


Solution

  • The problem was because of redirecting to other state first (to handle, loading, etc) on page load before redirecting back. This pattern isn't very compatible with how ui-router works. After I handled the loading functionality without redirecting to states initially, everything worked as expected.