AngularJS路由没有散列“#” – 不能得到它的工作

我已经阅读了这个post很多次了,我遵循了那里的指示,但是我无法得到这个工作。

AngularJS路由没有哈希'#'

我有一个Qt应用程序,发送一个请求到一个URL的URL。 该URL被路由到Angular代码。 我想改变这个不需要#。

这是我的Angular代码:

angular.module('app').config(function($routeProvider, $locationProvider) { $routeProvider // route for the home page .when('/', { templateUrl : 'home.html', controller : 'home' }) // route for the workitem page .when('/workitem/:identifier', { templateUrl : 'workitem.html', controller : 'workitem' }); $locationProvider.html5Mode(true); }); 

这是我的nginxconfiguration:

 server { listen 8000; server_name foo.bar.com; location / { include /usr/local/nginx/conf/mime.types; root /projects/larry/web; } } 

在/ projects / larry / web中有一个index.html,它用$ routeProvider加载JS模块。

当我去的url: http : //foo.bar.com : 8000/#/workitem/12345这工作正常。 JS被加载,并且$ routeProvider获取URL并做它应该做的事情。

但是,如果我省略#并转到http://foo.bar.com:8000/workitem/12345然后JS代码不加载,请求失败。

我怎样才能使这项工作没有哈希?

您还需要在您的html页面的<head>中添加<base href="/" />

下面的例子。

 <!DOCTYPE html> <html ng-app="app"> <head> <title>My Website</title> <base href="/" /> </head> <body> </body> </html> 

编辑

这将带你到一个GitHub帖子的答案。 https://gist.github.com/cjus/b46a243ba610661a7efb