Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI Router - Check if a state exists

I want something like this:

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

But it apparently won't work (it always goes with $state.go even when there's no parent state). How to correctly do a check if an particular state exists?

like image 218
softzer0 Avatar asked Jul 06 '16 14:07

softzer0


1 Answers

you could use $state.href which will return null if the state does not exist. See http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state

like image 161
FelixMelix Avatar answered Nov 17 '22 01:11

FelixMelix