Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Otherwise on StateProvider

Using angular-ui-router, How can I use the otherwise method on $stateProvider or how can I use it at all ?

like image 373
Adelin Avatar asked May 28 '13 13:05

Adelin


People also ask

What is UrlRouterProvider otherwise?

otherwise(rule: string | RawNg1RuleFunction): UrlRouterProvider. Defines the path or behavior to use when no url can be matched.

What is $stateProvider in AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.


1 Answers

You can't use only $stateProvider.

You need to inject $urlRouterProvider and create a code similar to:

$urlRouterProvider.otherwise('/otherwise'); 

The /otherwise url must be defined on a state as usual:

 $stateProvider     .state("otherwise", { url : '/otherwise'...}) 

See this link where ksperling explains

like image 65
Richard Keller Avatar answered Sep 21 '22 10:09

Richard Keller