AngularJS html5Mode 路由问题托管在 IIS 8.5 中

AngularJS html5Mode routing problems hosted in IIS 8.5

本文关键字:IIS html5Mode 路由 问题 AngularJS      更新时间:2023-09-26

当我尝试浏览我的 AngularJS 应用程序的路由时,我要么收到403.14 - Forbidden错误,要么收到404 - Not Found错误。

当我尝试导航到基本 URL 时,我得到一个 403。

示例:http://localhost/Board.WebApp/给出 403。

对于所有其他路线,我得到403。

示例:http://localhost/Board.WebApp/template1 给出 404。

似乎有什么问题?这是我的代码:

默认值.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>

路线.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模式下运行,则需要一些服务器端配置:服务器必须重写指向应用程序入口点的链接。