AngularJS IIS 8.5 中托管的 html5Mode 路由问题
AngularJS html5Mode routing problems hosted in IIS 8.5
当我尝试浏览我的 AngularJS 应用程序的路由时,我遇到 403.14 - Forbidden
错误或 404 - Not Found
错误。
当我尝试导航到基地 URL 时,我得到了 403。
Example: http://localhost/Board.WebApp/ gives a 403.
对于所有其他路由,我得到 403。
Example: http://localhost/Board.WebApp/template1 gives a 404.
好像是什么问题?这是我的代码:
default.html:
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" xmlns="http://www.w3.org/1999/xhtml" id="app">
<head>
<title>Board</title>
<link rel="stylesheet" href="css/app.css" />
<base href="/Board.WebApp/" />
</head>
<body ng-cloak>
<section id="local-content" ng-view></section>
</body>
</html>
routes.js
function (module, amd) {
'use strict';
var mod = angular.module('routes', ['ngRoute']);
mod.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: true
}); // for pushState routing support instead of # hash
$routeProvider
.when("/", amd.route(
{
templateUrl: 'views/home.html',
controller: 'eventController',
controllerUrl: 'app/controllers/eventController'
}))
.when("/template1", amd.route(
{
templateUrl: 'views/templates/template1.html',
controller: 'eventController',
controllerUrl: 'app/controllers/eventController'
}))
}]);
});
如果您想在 HTML5 模式下 运行,则需要一些 server-side 配置:服务器必须重写指向应用程序入口点的链接。
当我尝试浏览我的 AngularJS 应用程序的路由时,我遇到 403.14 - Forbidden
错误或 404 - Not Found
错误。
当我尝试导航到基地 URL 时,我得到了 403。
Example: http://localhost/Board.WebApp/ gives a 403.
对于所有其他路由,我得到 403。
Example: http://localhost/Board.WebApp/template1 gives a 404.
好像是什么问题?这是我的代码:
default.html:
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" xmlns="http://www.w3.org/1999/xhtml" id="app">
<head>
<title>Board</title>
<link rel="stylesheet" href="css/app.css" />
<base href="/Board.WebApp/" />
</head>
<body ng-cloak>
<section id="local-content" ng-view></section>
</body>
</html>
routes.js
function (module, amd) {
'use strict';
var mod = angular.module('routes', ['ngRoute']);
mod.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: true
}); // for pushState routing support instead of # hash
$routeProvider
.when("/", amd.route(
{
templateUrl: 'views/home.html',
controller: 'eventController',
controllerUrl: 'app/controllers/eventController'
}))
.when("/template1", amd.route(
{
templateUrl: 'views/templates/template1.html',
controller: 'eventController',
controllerUrl: 'app/controllers/eventController'
}))
}]);
});
如果您想在 HTML5 模式下 运行,则需要一些 server-side 配置:服务器必须重写指向应用程序入口点的链接。