所以我有以下的骨干路线:不调用路由器功能的骨干?
Nightbird.Routers.Errors = Nightbird.Routers.Core.extend({
routes: {
'server_error': 'serverError',
},
initialize: function(){
console.log('dasddasd');
},
serverError: function() {
console.log('asdasdasd');
var serverErrorView = new Nightbird.Views.ServerError();
serverErrorView.render();
}
});
它来到这个班,因为initialize
函数被调用,当这条线路的负载我看到:在控制台dasddasd
,但我确实没有看到asdasdasd
网址是localhost:9000/#server_error
有人可以解释我做错了什么吗?我不确定我还有什么可以提供进一步的信息,所以请索取任何额外的细节。
附加
以下是应用程序如何得到注册:
window.Nightbird = {
Models: {},
Collections: {},
Views: {},
Routers: {},
blogId: 0,
initialize: function() {
if (window.Development === undefined && window.Production === undefined) {
throw 'Production class (Production.config.js) cannot be missing. App Cannot load.';
}
if (window.Development !== undefined) {
this.blogId = window.Development.BLOG_ID;
} else {
this.blogId = window.Production.BLOG_ID;
}
new Nightbird.Routers.Posts();
new Nightbird.Routers.Errors();
if (!Backbone.History.started) {
Backbone.history.start();
} else {
Backbone.history.stop();
Backbone.history.start();
}
}
}
此类扩展:
Nightbird.Routers.Core = Backbone.Router.extend({
serverError: function(){
Backbone.history.navigate("server_error", {trigger: true});
}
});
为什么这样一个简单的抽象,因为这种方式的任何问题获取或发布或者你可以将你重定向到服务器错误路由。
然后在我的index.html
我做的:
<!DOCTYPE html>
<html>
<body>
<div id="manage">
</div>
</body>
<script src="js/compiled.js"></script>
<script>
Nightbird.initialize();
</script>
</html>
你有这样的代码:'''Backbone.history.start()''''? – 2014-08-29 16:03:24
@SlawaEremkin我更新了帖子 - 是的,我确实。 – user3379926 2014-08-29 16:05:18