I have been trying to find a way to implement angular routing which routes based on a condition rather than which link the user clicks
route1 -> view1 route2 -> view2
To add complication, the condition itself is evaluated on the result of a service. I am retrieving a set of items for my shopping cart checkout app. I need the shopping cart to route to view1 if the number of items is > 0. And a different route if it is 0.
if (itemListService.getItems().length > 0) --> route1
else --> route2
And because of this, the complication which arises is that the routing has to wait until the service result is evaluated before loading the corresponding view. In other words, the promise of the service has to be resolved.
I found the following post where someone suggested using 'resolve' configuration property within the routeprovider, but that only solves the issue of waiting for the service response. I'm not sure if it satisfies checking a condition based on the service response.
Redirecting to a certain route based on condition
Can someone help me with this? Would ui-router be able to implement this better than routeProvider?