Hashbang在角度应用中违约

时间:2017-01-19 05:09:27

标签: javascript angularjs routing angular-routing hashbang

最新版本的angular / angular-route 1.6.1是否默认使用hashbang?以这段代码为例,我必须使用#!链接到partials时,因为#/或#/ partial2不起作用。我认为你必须设置一个哈希前缀,但看起来它违反了这种行为:

<!DOCTYPE html>
<html ng-app='myApp'>
  <head>
  <title></title>
  <script src="bower_components/angular/angular.min.js"></script>
  <script src="bower_components/angular-route/angular-route.js"</script>

  <script>

    var myApp = angular.module('myApp', ['ngRoute']);
    myApp.config(function ($routeProvider) {
      $routeProvider
        .when('/',{
            templateUrl: 'partials/view1.html',
        })
        .when('/partial2',{
            templateUrl: 'partials/view2.html'
        })
        .otherwise({
          redirectTo: '/'
        });
    });

    myApp.controller('view1Controller', function ($scope) {
      $scope.sports = ['golf', 'basketball', 'hockey', 'tennis',    'football'];
    });
    myApp.controller('view2Controller', function ($scope) {
      $scope.message = 'We are using another controller';
    });
  </script>
</head>

<body>
  <div ng-app='myApp'>
    <a href="#!/">Partial 1</a> | <a href="#!/partial2">Partial 2</a>
    <div ng-view="">
    </div>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

起始角度为1.6.0,#!/成为路线的默认值。我基本上工作到版本直到#/ working,这是1.5.11。