我正在构建 AngularJS 应用程序,在构建第二个视图时遇到 URL 问题:
我的 appContact.js 如下所示:
(function () {
"use strict";
var app = angular.module("appContacts", ["simpleControls", "ngRoute"])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when("/", {
controller: "contactsController",
controllerAs: "vm",
templateUrl: "/views/contactsView.html"
});
$routeProvider.when("/details/:firstName", {
controller: "contactsDetailsController",
controllerAs: "vm",
templateUrl: "/views/detailsView.html"
});
$routeProvider.otherwise({ redirectTo: "/"});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
});
})();
在我的 HTML 中,我有这个链接:
<a asp-controller="Contact" asp-action="Details" ng-href="#/details/{{contact.firstName}}" >{{ contact.firstName}}</a>
当我将鼠标悬停在浏览器中时,我有正确的建议链接,例如:
**http://localhost:8000/#/details/Matthew**
但是当我单击链接导航到新页面时,URL 更改为
**http://localhost:8000/#%2Fdetails%2FMatthew**
将“/”更改为 %2 会使应用程序失败并显示空白页面。
您知道这是为什么以及如何纠正这个问题吗?
我已经读过类似的帖子,但它们似乎都不起作用,因为在编码的 URL 到达浏览器之前我无法访问它,并且错误就在那里。
Thanks
Rafael