如何为我的骨干应用程序创建子路由器? 我找到了一些代码,但无法使其正常工作(https://gist.github.com/1235317)。路由器创建后不会执行路由处理程序。
答案 0 :(得分:1)
将其添加到最后的构造函数
中// 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);
}