骨干路由器:在URL中摆脱排名第 [英] Backbone Router : Get rid of # in the URL
问题描述
我越来越骨干路由器的工作。
I'm getting backbone router to work
App.Router = Backbone.Router.extend({
routes: {
"todo": "todo"
},
todo: function() {
alert(1);
}
});
Backbone.history.start();
这工作得很好,当我转到网址:域:端口/#/ TODO
This works well when I goto url : domain:port/#/todo
我想这在URL中没有#的工作,我想在文件中提到将pushState的参数。
I want this to work without # in the URL, I tried putting pushState parameter as mentioned in the documents.
Backbone.history.start({pushState: true});
这只是重定向URL#与非散列有一个
This simply redirects # url to the non hashed one
域:端口/#/ TODO(重定向到==>)域:端口/ TODO
但是,当我直接访问这个网址
But when I visit this URL directly
域:端口/ TODO
这是行不通的:不能GET / TODO
it doesn't work: "Cannot GET /todo".
有什么办法,我可以在它而不#此URL工作的?
Is there any way, I can make this URL work without # in it?
推荐答案
您需要编写服务器端code为URL提供的页面。
You need to write server side code to deliver the page for the URL.
使用 pushState的
只是告诉浏览器的我用JS改变页面的内容,以便它匹配,如果你问这个URL,你会得到什么。
Using pushState
just tells the browser "I have used JS to change the content of the page so it matches what you would get if you ask for this URL".
它不会导致内容相匹配的网址,你所要做的,作为一个单独的任务。
It doesn't cause the content to match that URL, you have to do that as a separate task.
这篇关于骨干路由器:在URL中摆脱排名第的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!