问题描述
我看了这个帖子很多次,我也跟着指示,但我不能得到这个工作。
I have read this post many times, and I have followed the instructions there, but I cannot get this to work.
我有一个Qt应用程序,发送到URL的请求,在它#。该URL被路由到角code。我想改变这不需要#。
I have a Qt app that sends a request to a URL with a # in it. That URL is routed to the Angular code. I want to change this to not require the #.
这是我的角code:
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的配置:
This is my nginx config:
server {
listen 8000;
server_name foo.bar.com;
location / {
include /usr/local/nginx/conf/mime.types;
root /projects/larry/web;
}
}
在/项目/拉里/网络有一个index.html,它加载的$ routeProvider。
In /projects/larry/web there is an index.html, which loads the JS module with the $routeProvider.
当我去的网址:这工作正常。该JS被加载,而$ routeProvider获取URL和做什么它应该做的。
When I go to the URL: http://foo.bar.com:8000/#/workitem/12345 this works fine. The JS is loaded, and the $routeProvider gets the URL and does what it's supposed to do.
但是,如果我省略#,然后转到那么JS code未加载并请求失败。
But if I omit the # and go to http://foo.bar.com:8000/workitem/12345 then the JS code is not loaded and the request fails.
我怎样才能使这项工作没有散?
How can I make this work without the hash?
推荐答案
您还需要添加<基本href =//>
在< HEAD>
HTML页面的
You also need to add the <base href="/" />
in the <head>
of your html page.
下面的例。
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>My Website</title>
<base href="/" />
</head>
<body>
</body>
</html>
修改
这将带你到一个GitHub的后有了答案。
This will take you to a GitHub post with the answer. https://gist.github.com/cjus/b46a243ba610661a7efb
这篇关于AngularJS路由没有#'#' - 不能让它工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!