Nginx的配置工作,在HTML5模式angularjs路线 [英] Nginx config works with angularjs route in HTML5 mode

查看:131
本文介绍了Nginx的配置工作,在HTML5模式angularjs路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与angularjs路线nginx的配置文件中挣扎。

I am struggling with the nginx config file with angularjs route.

在我的情况,我有这些HTMLS:

In my case, I have these HTMLs:

index.html的
description.html
dashboard.html

dashboard.html 是一个与angularjs code。

The dashboard.html is the one with angularjs code.

下面是我当前的nginx的配置文件:

Here is my current nginx config file:

upstream panda.dev {
    server 127.0.0.1:3333 max_fails=3 fail_timeout=30s;
}

server {
    listen       80;
    server_name  panda.dev;
    root /Users/Jeremy/Documents/Projects/PandaUnion/web/converted-html;

    # serve static files directly
    location / {
        index index.html$args;
        try_files $uri$args $uri$args/ $uri/ /dashboard.html$args =404;
    }
}

下面是我的角度code:

Here is my angular code:

PandaUnion.controller('PandaController', function($routeParams, $location) {
  console.log($routeParams);
});

var templateURL = '/partials';

PandaUnion.config(function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
  return $routeProvider.when('/dashboard/:user_id', {
    templateUrl: templateURL + '/home.html'
  }).when('/dashboard/:user_id/setting', {
    templateUrl: templateURL + '/setting.html'
  }).when('/dashboard/:user_id/bill', {
    templateUrl: templateURL + '/bill.html'
  });
});

使用这个配置,我可以得到 dashboard.html 通过访问 /仪表板/ 123 ,但我可以'吨得到 123 作为routeParam的角度。

With this config, I can get dashboard.html via visiting /dashboard/123, but I can't get 123 as routeParam in angular.

这应该打印 {USER_ID:123} 当我访问 /仪表板/ 123 但我只看到一个空对象。

It should print {user_id: 123} when I visit /dashboard/123 but I only see an empty Object.

善有善报错在这里?请帮助...

What goes wrong here? Please help...

(对不起我的英文不好)

(sorry for my poor English)

推荐答案

有一个看AngularJS 教程。正如你可以看到,你必须通过$ routeParams对象的参数(在你的情况USER_ID)绑定。

Have a look at the AngularJS tutorial. As you can see there, you have to bind the parameter (user_id in your case) via the $routeParams object.

所以:


  1. 定义为一个控制器时,()语句

  2. 注入$ routeParams对象在控制器

  3. 绑定参数到$ scope对象

  4. 在您的模板确保你是在控制器范围内提到user_ID的
  5. 在当前

希望有所帮助。

这篇关于Nginx的配置工作,在HTML5模式angularjs路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆