angular路由的工作流程是什么?

What is the workflow of angular routing?

我正在使用 angula rjs routin,一切正常,但路由给我带来了一个奇怪的问题。当我在 index.html 页面上单击 link 时,url 如下所示

http://localhost:0000/Index.html#%2Fhome

它应该是这样的:

http://localhost:0000/Index.html#/home

当我将我的路由功能从“/home”更改为仅“/”时,我的应用程序运行良好,但我不明白我哪里出错了,以下是我的路由文件:

var app = angular
            .module("Demo", ["ngRoute"])
            .config(function ($routeProvider, $locationProvider) {
                $locationProvider.html5Mode(true);
                $routeProvider
                    .when("/home", {
                        templateUrl: "Templates/home.html",
                        controller: "homeController"
                    })
                    .when("/courses", {
                        templateUrl: "Templates/courses.html",
                        controller: "coursesController"
                    })
                    .when("/students", {
                        templateUrl: "Templates/students.html",
                        controller: "studentsController"
                    })
            })
            .controller("homeController", function ($scope) {
                $scope.message = "Home Page";
            })
            .controller("coursesController", function ($scope) {
                $scope.courses = ["C#", "VB.NET", "ASP.NET", "SQL Server"];
            })
             .controller("studentsController", function ($scope, $http) {
                 $http.get("StudentService.asmx/GetAllStudents")
                                        .then(function (response) {
                                            $scope.students = response.data;
                                        })
             })

下面是我的 index.html:

<!DOCTYPE html>
<html ng-app="Demo">
<head>
    <title></title>
    <script src="scripts/angular.min.js"></script>
    <script src="scripts/angular-route.min.js"></script>
    <link href="Styles.css" rel="stylesheet" />
    <script src="scripts/Script.js"></script>
    <base href="/"/>
    <meta charset="utf-8" />
</head>
<body>
    <table style="font-family: Arial">
        <tr>
            <td colspan="2" class="header">
                <h1>
                    WebSite Header
                </h1>
            </td>
        </tr>
        <tr>
            <td class="leftMenu">
                <a href="#/home">Home</a>
                <a href="#/courses">Courses</a>
                <a href="#/students">Students</a>
            </td>
            <td class="mainContent">
                <ng-view></ng-view>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="footer">
                <b>Website Footer</b>
            </td>
        </tr>
    </table>
</body>
</html>

所以,我按照给定的评论更新了 index.html 如下,这对我有用。谢谢!

<!DOCTYPE html>
<html ng-app="Demo">
<head>
    <title></title>
    <script src="scripts/angular.min.js"></script>
    <script src="scripts/angular-route.min.js"></script>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link href="Styles.css" rel="stylesheet" />
    <script src="scripts/Script.js"></script>
    <base href="/"/>
    <meta charset="utf-8" />
</head>
<body>
    <table style="font-family: Arial">
        <tr>
            <td colspan="2" class="header">
                <h1>
                    WebSite Header
                </h1>
            </td>
        </tr>
        <tr>
            <td class="leftMenu">
                <a href="/home">Home</a>
                <a href="/courses">Courses</a>
                <a href="/students">Students</a>
            </td>
            <td class="mainContent">
                <ng-view></ng-view>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="footer">
                <b>Website Footer</b>
            </td>
        </tr>
    </table>
</body>
</html>