最新版本的 Angular/Angular-Route 1.6.1 默认使用 hashbang 吗?就拿这段代码来说,我必须使用#!当链接到部分时,因为 #/或 #/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>
最佳答案
从 Angular 1.6.0 开始,#!/成为路由中的默认值。我基本上一直在研究版本,直到 #/工作,即 1.5.11。
关于javascript - Hashbang 在 Angular 应用程序中默认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41734185/