【问题标题】:How to get $urlRouterProvider.otherwise to redirect to a state instead of a path?如何让 $urlRouterProvider.otherwise 重定向到状态而不是路径?
【发布时间】:2016-11-03 09:57:51
【问题描述】:

我想重定向到一个状态而不是一个路径,不知道该怎么做。

【问题讨论】:

    标签: angularjs angular-ui-router state


    【解决方案1】:

    有类似的问答:

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

    我们可以得到注射器并要求$state

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

    see that 一个工作中的笨蛋

    【讨论】:

      【解决方案2】:

      .otherwise() 不必是字符串(url)或状态,它可以是一个聪明的决策者:

      你可以通过以下代码得到想要的结果:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-03
        • 2014-01-28
        • 2015-11-11
        • 2021-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多