AngularJS ui-router otherwise to state instead of url?

后端 未结 3 1623
傲寒
傲寒 2021-02-14 04:26

I am using AngularJS and ui-router and in my app.js. I have the following line:

$urlRouterProvider.otherwise(\'/\');

However

相关标签:
3条回答
  • 2021-02-14 04:30

    Try This.

    $urlRouterProvider.otherwise(function($injector, $location){
        $injector.get('$state').go('404');
    });
    
    0 讨论(0)
  • 2021-02-14 04:34

    I think you achieved that with this code

    $urlRouterProvider.otherwise(function($injector, $location){
      $injector.invoke(['$state', function($state) {
        $state.go('404');
      }]);
    }); 
    
    0 讨论(0)
  • 2021-02-14 04:51

    Just a small improvement to @kdlcruz's answer:

    $urlRouterProvider.otherwise(function($injector){
        $injector.invoke(['$state', function($state) {
            $state.go('404', {}, { location: false } );
        }]);
    });
    

    By doing that, you still able to keep the incorrect the URL and only state is changed.

    0 讨论(0)
提交回复
热议问题