admin管理员组文章数量:1335847
I have been watching the screencast from PeepCode on Backbone.js, and have done the coding with it.
I have finished the first part and now, I have a Router like this:
routes: {
'': 'home',
'blank': 'blank'
}
and also I have this to start the App:
$(function(){
window.App = new BackboneTunes();
Backbone.history.start({pushState: true});
});
Now, if I type http://localhost:9292/#blank in the URL bar, it redirects me to http://localhost:9292/blank, but if I type http://localhost:9292/blank directly, it gives a 404 message.
Is this normal or do I have an error here?
Thanks in advance.
I have been watching the screencast from PeepCode on Backbone.js, and have done the coding with it.
I have finished the first part and now, I have a Router like this:
routes: {
'': 'home',
'blank': 'blank'
}
and also I have this to start the App:
$(function(){
window.App = new BackboneTunes();
Backbone.history.start({pushState: true});
});
Now, if I type http://localhost:9292/#blank in the URL bar, it redirects me to http://localhost:9292/blank, but if I type http://localhost:9292/blank directly, it gives a 404 message.
Is this normal or do I have an error here?
Thanks in advance.
Share Improve this question asked Sep 23, 2011 at 15:48 Omid KamangarOmid Kamangar 5,7889 gold badges43 silver badges70 bronze badges2 Answers
Reset to default 8For those that thought the above answer was insufficient: What you want to do is enable your server to reroute all urls to your index.html page where Backbone.js will take care of the routing for you. The following steps will let you do this while still keeping the URL the same inside the address bar.
If you're using Apache as your container, you need to enable a mod_rewrite module inside your application's .htaccess file.
Inside your httpd file:
1) Make sure that your "Override" mand for your document root is enabled to "Override All" instead of "Override None"
2) Enable the mod_rewrite.so module by unmenting this line:
LoadModule rewrite_module modules/mod_rewrite.so
Inside your application's .htaccess file (if you don't have one, create one):
1) If you have a IfModule mod_rewrite.c module already written, then copy these lines into one of the modules:
RewriteEngine On
RewriteRule ^/[a-zA-Z0-9]+[/]?$ /index.html [QSA,L]
You should have something that looks like this:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^/[a-zA-Z0-9]+[/]?$ /index.html [QSA,L] </IfModule>
Edit
Note: In Apache 2.2+, you can now use FallbackResource instead of mod_rewrite, it requires fewer lines and acplishes the same thing.
You need to set up your server to return the same page for all of the URLs that Backbone routes to. Right now, it's only serving the page from the root URL.
本文标签: javascriptBackbonejs pushState is not working and gives a 404 errorStack Overflow
版权声明:本文标题:javascript - Backbone.js pushState is not working and gives a 404 error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742388108a2465445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论