html - AngularJS HTML5 嵌套路由

标签 html url angularjs

Angular :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 网址与嵌套路由一起使用?

最佳答案

对于单页应用程序,这就是您在 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;
    }
}

关于html - AngularJS HTML5 嵌套路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17154378/

相关文章:

html - 如何使用CSS将侧边栏右对齐?

javascript - ASP.NET MVC 5 网站中的 CSS 和 Javascript 以及图像在部署后不会显示

http - 查询字符串键是否区分大小写?

html - 仅使用 CSS,无限时间循环播放 30 张图像,创造出燃烧的火焰效果

php - 如何在 php 中检查当前 url

url - Grails createLink到项目根目录?

javascript - Angular 1 : How to reflect ng-model errors on another element?

javascript - 检查时 Bootstrap 按钮类重复,我该如何解决这个问题?

javascript - 如何将 td contenteditable 值绑定(bind)到 ng-model

javascript - 如何在 AngularJS 中交换 div 元素的顺序?