[英]AngularJS routing without the hash '#' - cannot get it work
我已经阅读了很多篇文章,并且按照那里的说明进行操作,但是我无法使其正常工作。
我有一个Qt应用程序,它向其中带有#的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);
});
这是我的nginx配置:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.