【发布时间】:2018-01-05 20:10:39
【问题描述】:
Angular2 应用程序已经运行良好。我一直在尝试通过添加 server.js 来使用该 angular2 应用程序实现 MEAN 堆栈,但我不确定为什么我找不到 index.html 网页没有出现在浏览器中。
我的文件夹结构是:
而 express.js 是:
var express=require('express');
var app=express();
app.use('/src',express.static(__dirname+'/src'));
app.get('/',function(req,res){
res.sendFile(__dirname+'/src/index.html');
});
app.listen(3000);
我什至尝试使用 ng build 来获取 dist 文件夹,并尝试指向 dist/index.html,但效果不佳。请支持。
编辑: index.html -src
<html lang="en">
<head>
<meta charset="utf-8">
<title>Something</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
index.html - 分布
<html lang="en">
<head>
<meta charset="utf-8">
<title>Something</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>
【问题讨论】:
-
浏览器控制台中的任何错误?
-
在 ngbuild 并指向 dist 文件夹的 index.html 之后,我得到 localhost/:14 GET localhost:3000/inline.bundle.js localhost/:14 GET localhost:3000/polyfills.bundle.js localhost/:14 GET localhost:3000/styles.bundle.js localhost/:14 GET localhost:3000/vendor.bundle.js localhost/:14 GET localhost:3000/main.bundle.js 404(未找到)
-
这样做
ng build --base-href .然后尝试 -
当我将
更改为 我在这里
,我可以在浏览器中查看“我在这里”。因此,问题在于加载组件。太腥了! -
是的,JS没有加载你得到404,这就是为什么我说做这个命令
ng build--base-href .
标签: javascript angular mean-stack mean.io