UI Router - check if state exists

I need something like this:

if ($state.get("^")) $state.go("^"); else $location.path('/');

But it apparently won't work (it always comes with $state.go , even if there is no parent state). How to correctly check if a specific state exists?

+6
source share
1 answer

you can use $ state.href, which will return null if the state does not exist. See http://angular-ui.imtqy.com/ui-router/site/#/api/ui.router.state . $ State

+5
source

All Articles