2014-03-06 22 views
1

我分叉了角度種子項目以嘗試angularJS,並且我正在面對URL的一些問題。 如何擺脫app/index.html部件來訪問index.html文件,以便 localhost:8000/app/index.html變爲localhost:8000?另外,它看起來像我定義的路線被忽略。Angular JS:如何擺脫URL中的app/index.html並停止顯示目錄內容

/* app/js/app.js */ 

var myApp = angular.module('myApp', [ 
    'ngRoute', 
    'myAppControllers' 
]); 

myApp.config(['$routeProvider', '$locationProvider', 
       function($routeProvider, $locationProvider) { 
    /* I can't even find how to access these urls */ 
    $routeProvider.when('/', { 
    templateUrl: 'partials/home.html', 
    controller: 'HomeCtrl' 
    }) 
    .when('/navigation', { 
    templateUrl: 'partials/file-navigation.html', 
    controller: 'FileNavigationCtrl' 
    }) 
    .otherwise({ 
    redirectTo: '/' 
    }); 

    $locationProvider.html5Mode(true); 
}]); 

/* app/js/controllers.js */ 

var myAppControllers = angular.module('myAppControllers', []); 

myAppControllers.controller('FileNavigationCtrl', function($scope) { 
    $scope.files = [ /* some files */ ]; 
}); 

myAppControllers.controller('HomeCtrl', function($scope) { 
    $scope.user = 'TestUser'; 
}); 

我怎樣才能到達導航頁面的例子?我想:

  • 本地主機:8000 /導航
  • 本地主機:8000 /應用/導航
  • 本地主機:8000 /應用/ index.html的/導航
  • 本地主機:8000 /應用/ index.html的#/導航

並沒有一個工作,最後一個,但是,將URL更改爲localhost:8000 /#%2Fnavigation,而其他人返回404錯誤。

+0

嘗試'http:// localhost:8000/app /' –

+0

它只顯示app目錄的內容 –

回答

0

爲了擺脫你需要改變這個例子中的服務器部分index.htmlhttps://github.com/angular/angular-seed/blob/master/scripts/web-server.js

服務器嘗試解析URI和服務無論是從磁盤文件或目錄列表。您可以添加邏輯服務index.html如果請求/,東西沿線

if (path === './') { process.chdir('app') return self.sendFile_(req, res, 'index.html') }

不過,我不認爲你應該在現實生活中使用它。得到自己express並從那裏開始。