Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Grunt生成后未找到ngRoute:404_Angularjs_Nginx_Gruntjs_Ngroute - Fatal编程技术网

Angularjs Grunt生成后未找到ngRoute:404

Angularjs Grunt生成后未找到ngRoute:404,angularjs,nginx,gruntjs,ngroute,Angularjs,Nginx,Gruntjs,Ngroute,我有一个AngularJS项目,它有两个视图/设置和/。app.js文件如下所示: .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { $routeProvider .when('/', { templateUrl: './views/bill.html', controller: 'BillCtrl' }) .w

我有一个
AngularJS
项目,它有两个视图<代码>/设置和
/
app.js
文件如下所示:

.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {

  $routeProvider

  .when('/', {
      templateUrl: './views/bill.html',
      controller: 'BillCtrl'
  })

  .when('/settings', {
    templateUrl: './views/settings.html',
    controller: 'SettingsCtrl'
  })

  .otherwise({
      redirectTo: '/'
  });

  $locationProvider.html5Mode(true);

}]);
其中定义了所有路线

然后我有
app/views/bill.html
&
app/views/settings.html

现在,
grunt-serve
在我可以使用
ngHref
进入任何视图的地方都能完美运行。问题是当我执行
grunt build
并将
nginx
指向build目录(路径是
/kds
)时,我会看到一个
GEThttp://localhost/views/settings.html 404(未找到)

路径应该是相对的,因此应该是
GEThttp://localhost/kds/views/settings.html
但事实并非如此。这是怎么回事

这看起来更像是一个糟糕的服务器配置。或者是建筑把我搞得一团糟

服务器指令为

位置/kds{
别名/Users/asheshambasta/code/kds/dist/;
index.html index.htm;
}

编辑(完整
app.js

应用程序所需的所有文件:

  <!-- build:js({.tmp,app}) scripts/scripts.js -->
  <script src="scripts/app.js"></script>
  <script src="scripts/apiservice.js"></script>
  <script src="scripts/lib.js"></script>
  <script src="scripts/class/bill.js"></script>
  <script src="scripts/class/item.js"></script>
  <script src="scripts/class/course.js"></script>
  <script src="scripts/controllers/main.js"></script>
  <script src="scripts/controllers/bill.js"></script>
  <script src="scripts/controllers/settings.js"></script>
  <!-- endbuild -->

您正在将网站放在主机的子文件夹下

例如:

http://localhost/kds
因此,当您使用html5使ng route工作时,它将理解您需要移动到“/”,因为没有定义“/kds”

您可以使用的一个技巧是使用

把这个放到你的


...

这将使您的所有路由或模板都以该基为前缀。

最后我需要的是动态设置基href。另外,
base href
还有一些缺陷:相对路径应该有尾随和前导
\
;使用javascript,您可以将其设置为:

  <script>
    document.write("<base href='" + document.location.pathname + "' />");
  </script>

文件。填写(“”);

恐怕这不适合我。现在,它开始查找根
/
路径中的所有内容,应用程序失败。如果找不到用户名/密码,我也会在我的
app.run中找到
$location.path('/settings')
,但这不是问题所在。我对如何获得源文件有点困惑。我的建议是,当你的所有来源都在你主机的子路径中时。示例all在路径/kds中。请添加应用程序所需的所有文件的完整路径。例如:app.js处于打开状态,settings.html处于打开状态,依此类推。我想你的问题在于配置。我已经添加了index.htmly中包含的所有文件。你的问题不在于javascript文件。这是因为路径角度需要计算。当您告诉templateUrl:“/views/bill.html”时,您是在告诉angular在
localhost/views/bill.html
打开chrome调试工具并检查Nagiviation选项卡,查看angular链接试图查找的内容。他们尝试从templateUrl中删除“/”。
<html>
<head>
    <base href="/kds">
</head>
<body>
    ...
</body>
  <script>
    document.write("<base href='" + document.location.pathname + "' />");
  </script>