角度路由问题

时间:2014-09-16 13:56:25

标签: angularjs firebase

我正在尝试使用Firebase应用程序设置基本角度路由并且遇到困难

我的index.html是:

<html ng-app="SampleApp">
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js"></script>
 <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>
 <script src="https://cdn.firebase.com/js/client/1.0.18/firebase.js"></script>
 <script src="https://cdn.firebase.com/js/simple-login/1.6.3/firebase-simple-login.js"></script>
 <script src="https://cdn.firebase.com/libs/angularfire/0.8.0/angularfire.min.js"></script>
 <script src="app.js"></script>
</head>

<body>
<nav class="navbar>My Navbar</nav>

<div ng-view></div>


</body>
</html>

我的观点/ main.html是

<div>Main.html</div>

我的依赖是

var app = angular.module('sampleApp', ['ngRoute', 'firebase', 'ui.bootstrap']);

我的配置是

app.config(function($routeProvider, $locationProvider) {
    $routeProvider.
      when('/app/doctors', {
        templateUrl: 'views/main.html',
        controller: 'SampleCtrl'
      }).
      otherwise({
        redirectTo: '/'
      });

    $locationProvider.html5Mode(true);

})

我还应该补充说文件夹结构是

project
  app
   views
     main.html
   app.js
   index.html

每当我试图点击

localhost:8000/app/doctors I get a 404 Error. 

如果我去localhost:8000 / app我被重定向到localhost:8000。如果我转到localhost:8000,我会看到目录结构,可以单击app转到index.html,路由被重写为localhost:8000

我也尝试过localhost:8000 /#/ app / doctor,没有运气

2 个答案:

答案 0 :(得分:3)

除非您已将your routes配置为use html5mode,否则您需要在URL中包含一个hashbang(基于上面的示例):

localhost:8000#!/app/doctors

如果您已将路由配置为使用html5mode,则需要在服务器上设置URL重写。 apachefirebase hosting

答案 1 :(得分:2)

我认为您的网络服务器正在尝试为localhost:8000 / app / doctors提供服务,而不是让应用程序有机会为页面提供服务。

尝试配置您的网络服务器,以便将所有请求路由到您的应用所在的网页。