我创建了这个Plunker并添加了一个简单的路由。但由于某些原因,路由不起作用。我想在点击删除按钮时重定向到#/delete,但什么也没发生。
script.js:
var appRoot = angular.module('myNgApp', ['ngRoute', 'ui.bootstrap']);
appRoot.config([
'$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', { templateUrl: 'ngIndex.html', controller: 'IndexCtrl' })
.when('/delete', { templateUrl: 'delete.html', controller: 'DeleteCtrl' })
.otherwise({ redirectTo: '/' });
}
]);
ngIndex.html:
<a class="btn btn-danger" href="#/delete">Delete</a>
所以这是因为带有哈希前缀的angular 1.6路由发生了变化。因此,取而代之的是og"hashprefix现在是"!">
由于aa077e8,$location hash bang使用的默认哈希前缀URL已从空字符串('')更改为bang('!')。如果您应用程序不使用HTML5模式,或者正在以下浏览器上运行不支持HTML5模式,并且您没有指定自己的模式hash前缀,则客户端URL现在将包含一个!前缀对于例如,URL将变为mydomain.com/#/a/b/cmydomain.com/#/a/b/c。
如果您确实希望没有哈希前缀,那么您可以恢复向应用程序添加配置块的先前行为:
appModule.config(["$locationProvider",函数($locationProvider){
$locationProvider.hashPrefix(");}]);源
我发表了一篇类似的文章,提出了可能的解决方案:角度未正确布线。URL为localhost:8081/#/#pageName
来自其他帖子:
该怎么办
1。将HTML5模式设置为true
$locationProvider.html5Mode(true);
并且在html中在html报头中设置基:
<base href="/">
最后将<a ng-href="#pagename">
更改为
<a ng-href="pagename">
2.从1.5返回到旧行为-手动设置哈希前缀这将使您的应用程序如您在问题中所期望的那样工作
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
在您的示例中
要确定这就是问题所在,您可以更改
$window.location.href = '#/delete';
至
$window.location.href = '#!/delete';