【发布时间】:2015-11-06 16:50:31
【问题描述】:
很抱歉,我对 node 很陌生。我已经坚持了几个小时了。
server.js
app.use(express.static(__dirname + "/public"));
app.get('/', function(req, res){
res.sendFile(path.resolve(templatesPath + 'index.html'));
});
app.get('*', function(req, res){
res.sendFile(path.resolve(templatesPath + 'index.html'));
});
index.html 是一个 Angular 应用程序。我的第一级路由使用 Angular 的 HTML5 路由可以正常工作,例如。 “http://lh:3000/staff”或“http://lh:3000”
但是如果我添加另一个级别或路由参数,例如“http://lh:3000/staff/”或“http://lh:3000/staff/test”Express 似乎忽略了 express.static,而是使用 get 通配符将我的所有文件转换为 index.html,因此我的分页符。
感谢您的帮助回答者
在二级路由中,它正在加载 index.html 中引用的资源,相对于二级路由。我的临时解决方案是添加: app.use('/files/',express.static(path.join(__dirname + "/public"))); 但我现在意识到最好改变我的解决方案。
【问题讨论】: