2

I want to redirect to a state instead of a path, can't quite figure out how to do it.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Flávio Carvalho
  • 149
  • 2
  • 11

2 Answers2

3

There is a similar Q & A:

How not to change url when show 404 error page with ui-router

We can get injector and ask for a $state

$urlRouterProvider.otherwise(function($injector, $location){
   var state = $injector.get('$state');
   state.go('404');
   return $location.path();
});

see that for a working plunker

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
1

The .otherwise() does not have to be a string (url) or a state, it could be a smart decision maker:

You can get the desired result by following code:

$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('yourState');
}]);
});
Avantika Saini
  • 792
  • 4
  • 9