【发布时间】:2018-05-09 16:42:11
【问题描述】:
使用 URL 参数时,例如books/1,由于某种原因,快递应用无法找到和服务Index.js。
我使用的是绝对路径,但即使我的 express 应用程序在使用参数在 url 处刷新时仍无法找到 Index.js。
正如您在屏幕截图中看到的那样,它没有提供Index.js,而是找不到它,而是以Index.js 的形式提供html 文件。
我正在使用catch-all solution,它在用 url 参数刷新之前效果很好:
app.use(express.static(path.resolve(__dirname, '..', 'build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'build', 'index.html'));
});
我什至尝试为/Index.js 设置特定路线,但没有成功。
app.use(express.static(path.resolve(__dirname, '..', 'build')));
app.get('/Index.js', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'build', 'Index.js'))
});
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'build', 'index.html'));
});
我也尝试过使用serve-static 而不是express.static,但没有帮助。
如果有人有兴趣看看,我已经在repo 中复制了这个问题。
这个项目的前端在reason-react。
【问题讨论】:
-
从
Index.js的<script>标记的src属性中删除./
标签: javascript node.js express