$routeProvider.when('/', ...) 在 html5 模式打开时无效

$routeProvider.when('/', ...) has no effect, when html5 mode is on

问题解决方法:url你写的base标签应该有尾部斜线。

我有以下路由配置,但如果 html5 模式打开,则不会请求模板。没有错误,没有尝试从服务器获取资源。 更改基数 url 或使用 hasPrefix('!') 设置前缀都不会对此行为产生影响

   angular
        .module('beneficiaryBanks')
        .config(configRoutes);

configRoutes.$inject = ['$routeProvider','$locationProvider'];
function configRoutes($routeProvider, $locationProvider) {
    $routeProvider
        .when('/',
        {
            controller: 'beneficiaryBanksListController',
            controllerAs: 'listVM',
            templateUrl: 'BeneficiaryBanksList.cshtml'
        });
    $locationProvider.html5Mode(true);
}

看起来 angular 与当前 url 与“/”不匹配。

更新 1
调试显示对于 url http://localhost:8080/APS/Home/BeneficiaryBanksModule 和基地址 APS/Home/BeneficiaryBanksModule angular 将路由视为 /BeneficiaryBanksModule/ 不匹配,而路由变为a / 当 html5 模式被禁用时。

如我所见here,为了实现 AngularJS 和启用 html5 模式的 IIS Express 的这种组合,您可能需要进行一些配置。

我不知道你是否阅读了这篇文章,但有一些技巧可以让它发挥作用。

那是因为您的请求是由服务器本身处理的,而不是由您的 angular 应用程序处理的。

尝试阅读一些有关如何设置服务器以使用 html5 模式的文章:

https://dzone.com/articles/fixing-html5mode-and-angular http://www.thinkovator.com/blog/post/angularjs-html5-mode-and-iis-rewrite/

希望对你有帮助。

问题出在基本标签中。如果它不以斜杠结尾 / angular 将最后一部分视为文件名并删除它。

这就是为什么我看到 /BeneficiaryBanksModule 而不是 /