为什么$ locationProvider.html5Mode导致Infinite $ digest循环?

时间:2015-02-18 13:58:09

标签: angularjs

如果我设置$locationProvider.html5Mode(true),我的应用程序将返回:10 $digest() iterations reached. Aborting! (...)。我的代码片段在下面。

我的路线配置:

function configRoutes($stateProvider, $urlRouterProvider, $locationProvider, routeConfigProvider) {
  var routes = routeConfigProvider.$get();

  $locationProvider.html5Mode(true);

  $urlRouterProvider.otherwise('/default');

  $urlRouterProvider.when('/', '/route1');
  $urlRouterProvider.when('/route1', '/route1/route11');
  $urlRouterProvider.when('/route2', '/route2/route22');

  // Register all routes.
  for (var i = 0; i < routes.length; i++) {
    var route = routes[i];
    $stateProvider
      .state(route.state, route.options);
  }
}

我的web.config文件:

<rewrite>
  <rules>
      <rule name="Main Rule" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
      </rule>
  </rules>
</rewrite>

1 个答案:

答案 0 :(得分:3)

不要使用

  

$ urlRouterProvider.otherwise( '/默认');

替换为:

$urlRouterProvider.otherwise(function ($injector, $location) {
     var $state = $injector.get("$state");
     $state.go("default.state");
 });

将“default.state”替换为默认状态