3

角度:1.1.5

我去:http://xxxxx.com/route1/route2/route3 并被/route3触发而不是在route1/route2/route3 HTML5 模式关闭的情况下正常工作...... :(

Nginx 配置

location / {
    index index.html;
    try_files $uri $uri/ /index.html?$args;
}

我的应用配置

$routeProvider.when('/route1/route2/route3', {
        templateUrl: '/views/home.html',
        controller: 'HomeCtrl'
    });

$routeProvider.when('/route3', {
        templateUrl: '/views/home.html',
        controller: 'HomeCtrl'
    });

$locationProvider.hashPrefix('!');
$locationProvider.html5Mode(true);

$location日志:

$$protocol: "http", $$host: "xxxxxx"…}
$$absUrl: "http://xxxxxxx.com/route1/route2/route3"
$$hash: ""
$$host: "10.44.11.73"
$$path: "/route3"
$$port: 80
$$protocol: "http"
$$replace: false
$$url: "/route3"

如何更改我的设置以使 HTML5 url 与嵌套路由一起使用?

4

2 回答 2

3

对于单页应用程序,这就是您在 NGINX 配置中所需要的全部内容:

server
{
    server_name example.com *.example.com;
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;
    root /var/www/html/example;
    index index.html;
    location / {
       try_files $uri /index.html;
    }
}
于 2013-06-17T19:18:22.233 回答
3

添加

<base href="/">

到你的index.html.

于 2014-06-25T00:06:50.493 回答