Javascript Angular JS:如何去掉url中的app/index.html并停止显示目录内容

Javascript Angular JS:如何去掉url中的app/index.html并停止显示目录内容,javascript,angularjs,url,routes,Javascript,Angularjs,Url,Routes,我分叉了AngularSeed项目来尝试angularJS,我在URL方面遇到了一些问题。 如何摆脱app/index.html部分来访问index.html文件,以便 localhost:8000/app/index.html是否成为localhost:8000?而且,看起来我定义的路由被忽略了 /* app/js/app.js */ var myApp = angular.module('myApp', [ 'ngRoute', 'myAppControllers' ]); my

我分叉了AngularSeed项目来尝试angularJS,我在URL方面遇到了一些问题。 如何摆脱app/index.html部分来访问index.html文件,以便 localhost:8000/app/index.html是否成为localhost:8000?而且,看起来我定义的路由被忽略了

/* 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/应用程序/导航
  • localhost:8000/app/index.html/navigation
  • localhost:8000/app/index.html#/navigation

但是,最后一个将URL更改为localhost:8000/#%2Fnavigation,而其他的则返回404错误。

要摆脱
index.html
,您需要更改本例的服务器部分

服务器尝试解析URI并提供来自磁盘的文件或目录列表。如果请求了
/
,您可以添加逻辑来服务
index.html

if(路径=='./')){
process.chdir('app')
返回self.sendFile(req,res,'index.html')
}


然而,我认为你不应该在现实生活中使用它。从那里开始。

试试
http://localhost:8000/app/
它只显示应用程序目录的内容