繁体   English   中英

ngRoute返回404找不到错误

[英]ngRoute return 404 Not Found error

我正在使用AngularJS构建一个简单的个人联系人管理应用程序。 我将所有文件放入Mac机器的htdocs/angular-contacts/文件夹中。

在此处输入图片说明

的index.html

<!DOCTYPE html>
<html ng-app='ContactsApp'>
    <head>
        <title>Contacts</title>
        <base href='/'></base>
    </head>
    <body>
        <h1>Contacts</h1>
        <div ng-view=""></div>
        <script src='/angular-contacts/jquery-2.1.3.min.js'></script>
        <script src='/angular-contacts/angular.min.js'></script>
        <script src='/angular-contacts/angular-route.min.js'></script>
        <script src='/angular-contacts/angular-route.min.js.map'></script>
        <script src='/angular-contacts/app.js'></script>
        <script src='/angular-contacts/controller.js'></script>
    </body>
</html>

app.js

angular.module('ContactsApp', ['ngRoute']);
    .config(function($routeProvider,$locationProvider){
        $routeProvider
            .when('/contacts',{
                controller: 'ListController',
                templateUrl: 'list.html'
            });
        $locationProvider.html5Mode(true);
    });

controller.js

angular.module('ContactsApp')
    .controller('ListController',function($scope){
        $scope.contacts = [];
    })

list.html

<p>List views...</p>

为什么我去http://localhost:8888/angular-contacts/contacts ,却收到404 Not Found错误。

如何解决这个问题? 如何加载list.html

注意事项

  1. 我正在使用MAMP(Apache)。
  2. AngularJS:v1.3.14
  3. 角线:v1.3.14

那是因为

$routeProvider
    .when('/contacts',{
        controller: 'ListController',
        templateUrl: 'list.html'
    });

期望使用http://localhost:8888/contacts位置,而不是http://localhost:8000/angular-contacts/contats位置。

您应该在路由声明中添加前缀,或者甚至更好地配置虚拟主机 ,这样您就可以使用真实域,而不是本地主机的子目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM