简体   繁体   English

Backbone.js URL路由

[英]Backbone.js URL Routing

When setting up routes on backbone.js, it seems the framework automatically preprends # to it. 在backbone.js上设置路由时,框架似乎会自动为其预先发送#。 Ie

routes : { "example/:id" : "handler" },

will match a link of www.example.com/#example/123 将匹配www.example.com/#example/123的链接

Is it possible to add the hashtag later on in the url? 是否可以稍后在网址中添加主题标签? I'm essentially trying to build my app as www.example.com/text/#example/123 (notice the text/ before the #). 我实际上是在尝试将我的应用程序构建为www.example.com/text/#example/123(注意文本/#之前)。

Is there anyway of doing this without altering the backbone.js framework itself? 无论如何这样做而不改变backbone.js框架本身?

If your server serves the page containing your app to www.example.com/text , then the backbone router will handle urls like www.example.com/text#example/123 . 如果您的服务器将包含您的应用的页面提供给www.example.com/text ,那么骨干路由器将处理www.example.com/text#example/123网址。 It probably isn't advisable (even if your server supports it) to serve your page on www.example.com/test/ , because that url indicates that it is a folder, not a particular page. 可能不建议(即使您的服务器支持它)在www.example.com/test/上提供您的页面,因为该URL表示它是文件夹,而不是特定页面。

The backbone router pretty much ignores the baseurl (except for storing it and using it with pushState and popState), so you can serve your page on any url you want. 骨干路由器几乎忽略了baseurl(除了存储它并使用pushState和popState),因此您可以在任何您想要的URL上提供页面。

Hope htis helps. 希望htis有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM