Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.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 将所有路由或路径发送到_Angularjs_Node.js - Fatal编程技术网

Angularjs 将所有路由或路径发送到

Angularjs 将所有路由或路径发送到,angularjs,node.js,Angularjs,Node.js,在我的节点js app.js中,我希望无论url是什么,它都会转到我的angular/html页面,即begin.html,app.js位于服务器文件夹中,begin.html位于我项目的客户端文件夹中。就像:- -Project ----Server ---------app.js ----Client ---------begin.html 我应该在app.js中键入什么,以便所有URL都转到begin.html,我使用的是角度路由??我想这有点像 var begin=require('.

在我的节点js app.js中,我希望无论url是什么,它都会转到我的angular/html页面,即begin.html,app.js位于服务器文件夹中,begin.html位于我项目的客户端文件夹中。就像:-

-Project
----Server
---------app.js
----Client
---------begin.html
我应该在app.js中键入什么,以便所有URL都转到begin.html,我使用的是角度路由??我想这有点像

var begin=require('../Client/begin.html);
app.use('*',begin);

如果您要让所有的路由返回到那个HTML页面,那么您可以使用一个web服务器,比如静态地服务那个目录

看起来您正在使用Express,但这只是一个猜测。如果您希望从Angular端向Node.js端发出HTTP请求,那么您可能希望默认响应返回HTML,但仍然能够允许请求通过。我将考虑使用express中的静态方法公开静态目录,同时仍然允许您构建其他路由,即api路由

它可能看起来像这样:

// Already created express app above

/*
  This will default to using index.html from
  your Client directory and serve any other resources
  in that directory.
*/
app.use(express.static('../Client'));

// Any other routes

app.listen(3000); // Or whatever your port is
或者,您也可以使用404错误处理程序样式实现它,并返回默认文件:

/*
  This comes after all of your other
  route and middleware declarations and
  before the .listen() call
*/
app.use(function(req, res, next) {
  res.sendFile(path.join(__dirname + '/../begin.html'));
});

如果这对你有用,请接受这个答案,这样它也能帮助其他人。谢谢