Ui 路由器无法使用 Nodejs 找到视图

Ui router Couldn't find views with Nodejs

我正在开发 nodejs 应用程序,我们使用 Ui 路由器来实现单页应用程序,我在节点 js 中创建了控制器来加载具有 angular 脚本和库的布局,并且然后我尝试浏览我在 ui router 中定义的路由,每次我在控制台中收到错误说 "angular.js:8081 GET http://localhost:2405/Views/Partials/Know-me.html 404 (Not Found)" 我无法指定问题

这是一些代码:

Node.js 控制器

app.get("/",function(req , res){
    res.render("Template.ejs"); // this is the layout
});

布局脚本:

<script src="http://code.angularjs.org/1.2.13/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
<script src="../../angular_js/app_angular.js"></script>

和 app_angular 脚本:

var appmodule = angular.module('mainApp',[ui.router]);

 appmodule.config(function($stateProvider , $urlRouterProvider ,   $locationProvider){
     $urlRouterProvider.otherwise('/things');

     $stateProvider
     .state('me',{
         url : '/me',
         templateUrl :  '/Views/Partials/Know-me.html'
     })
     .state('amir',{
         url : '/amir',
         templateUrl : '/Know-me-amir.html'
     });
     //$locationProvider.html5Mode(true);
 });

项目结构:

-- 查看

--- 共享

----Temaplte.ejs

--- 偏音

----知道-me.html

-- 脚本

--- angular_js

----angular_app.js

问题是: ejs 文件在服务器上呈现。 AngularJS(客户端)尝试获取 'Views/Partials/Know-me.html'。从客户的角度来看,这个 html 不存在。

请执行以下操作:

  1. 添加 public 文件夹。
  2. 使用 express.static()
  3. 服务 public 文件夹
  4. 将 html 文件移动到此目录:public/Views/Partials/Know-me.html
  5. 尝试访问 http://localhost:2405/Views/Partials/Know-me.html - 如果您看到了 know-me 的内容 - 您就可以开始了!

现在您的客户端将找到异步加载的 html 文件。