Backbone.history.navigate和this.router.navigate之间的区别是什么

时间:2017-05-10 04:51:09

标签: javascript backbone.js backbone-routing

Backbone.history.navigatethis.router.navigate之间的区别是什么?

为什么有时候前者会在以后工作?

1 个答案:

答案 0 :(得分:1)

如果查看Backbone source,您会看到$cfg['Servers'][$i]['password']='' 只是$cfg['Servers'][$i]['password']='NO'. 的代理,您可以在任何地方呼叫,而无需路由器实例。

Router.prototype.navigate

路由在global, namespaced in Backbone, History instance处理。

这是为了让开发人员创建自己的Backbone.history.navigate类,然后覆盖// Simple proxy to `Backbone.history` to save a fragment into the history. navigate: function(fragment, options) { Backbone.history.navigate(fragment, options); return this; }, 属性以全局更改路由行为。

History类的记录不多,但它是well commented in the source

此外,在Backbone.history类中拥有History代理可以直接在路由器中挂钩我们自己的行为。

至于为什么有时它不起作用可能是因为你试图在navigate不存在的类中Router

相关问题