javascript Backbone.js URL 路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6977017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:33:35  来源:igfitidea点击:

Backbone.js URL Routing

javascriptbackbone.jshashbang

提问by bijanv

When setting up routes on backbone.js, it seems the framework automatically preprends # to it. I.e.

在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 #).

是否可以稍后在 url 中添加主题标签?我基本上是在尝试将我的应用程序构建为 www.example.com/text/#example/123(注意 # 之前的 text/)。

Is there anyway of doing this without altering the backbone.js framework itself?

有没有办法在不改变backbone.js框架本身的情况下做到这一点?

回答by idbentley

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. 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/text,那么主干路由器将处理www.example.com/text#example/123. 可能不建议(即使您的服务器支持它)在 上提供您的页面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 有帮助。