骨干js子路由器

Backbone js subRouter

本文关键字:路由器 js 骨干      更新时间:2023-09-26

如何为主干应用程序创建子例程?我找到了一些代码,但无法正常工作(https://gist.github.com/1235317)。创建路由器后不执行路由处理程序。

将其添加到最终的构造函数中

// grab the full URL
var hash = Backbone.history.getHash();
// check if there is already a part of the URL that this subview cares about...
var hashPart = hash.substr(prefix.length + 1, hash.length);
// ...if so, trigger the subroute immediately.  this supports the case where 
// a user directly navigates to a URL with a subroute on the first page load.
if (hashPart && hashPart != "") {
    Backbone.history.loadUrl(prefix + hashPart);
}