Flávio Carvalho Flávio Carvalho - 5 months ago 58
AngularJS Question

How to get $urlRouterProvider.otherwise to redirect to a state instead of a path?

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

Answer

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

Comments