Javascript 主干,快速发送文件提供错误路径
我正在使用express和backbone制作一个单页应用程序 在我的server.js中,我使用app.get/app.post/app.update等设置了REST调用。。 在文件的末尾,我有一条路径来加载我们的前端代码Javascript 主干,快速发送文件提供错误路径,javascript,jquery,node.js,backbone.js,Javascript,Jquery,Node.js,Backbone.js,我正在使用express和backbone制作一个单页应用程序 在我的server.js中,我使用app.get/app.post/app.update等设置了REST调用。。 在文件的末尾,我有一条路径来加载我们的前端代码 // load our main backbone javascript file app.get('/*', function(req, res){ // we're not sending the correct location of the file.
// load our main backbone javascript file
app.get('/*', function(req, res){
// we're not sending the correct location of the file.
res.sendfile('public/index.html');
});
一切都按计划进行,直到我不在localhost:3000时点击刷新/
例如,如果我在localhost:3000/user/300并点击刷新,那么我会收到这个错误消息
“未捕获的语法错误:意外令牌”
-app.js第2行(我们的主干文件)
页面上没有加载任何内容,只是空白
是否没有正确加载文件?你知道为什么会这样吗
`Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/r/app.js".`
这也是我在chrome控制台中收到的错误消息
更新:所以我改变了
Backbone.history.start({pushState:true})代码>到
Backbone.history.start();
现在一切正常,我可以毫无错误地刷新页面。但是,URL现在有一个哈希..=/有人能给我推荐一种解决问题的方法,这样我就不必在url中使用哈希了吗 你是不是正在使用app.use()
将express.static()
中间件放在该路径上方的某个位置?app.use(express.static(u dirname+/public));是的,我在顶部设置了它,将html文件中的/r/app.js
更改为/public/r/app.js
,静态文件的前缀为/public
.hm。。很抱歉没有正确描述我的问题。但是,如果我在localhost:3000以外的任何地方刷新页面,我的服务器似乎找不到app.js文件。例如,如果我刷新localhost:3000/user/3000上的页面,我想我的服务器会将我指向localhost:3000/user/app.js,如果我刷新localhost:3000/poll/1234121上的页面,它会将我指向localhost:3000/poll/app.js,这显然是错误的。My app.js与index.html一起位于公用文件夹中。我正在使用页面底部的标签从index.html加载app.js。