我似乎无法解决这个极其简单的问题。
我有一个Backbone/Marionnette应用程序,其中我将路由器定义为:
app.utils.AppRouter = Backbone.Marionette.AppRouter.extend({
initialize: function(){
this.route("", "home", function(){
console.log("In home!");
app.layout.content.show(new app.views.BrowseRestaurantsLayout());
});
this.route("account", "account", function(){
console.log("In account!");
app.layout.content.show(new app.views.AccountView());
});
}
});在代码中的其他地方,我需要导航到#account页面,所以我调用:
app.router.navigate('account', {trigger:true});我可以看到网址更改为#account,我的AccountView页面确实出现了一瞬间,然后消失,并被主页取代。
当我触发更改时,控制台显示为:
In account!
In home! 我遗漏了什么?
发布于 2012-08-10 04:05:22
您的主路由可能是一个包罗万象的路由,它是在您的帐户路由之后调用的。
当您将路由更改为此路径时会发生什么情况?
this.route("/", "home", function(){
console.log("In home!");
app.layout.content.show(new app.views.BrowseRestaurantsLayout());
});或者这可能是路线的顺序。最后尝试添加家庭路由器。
发布于 2013-03-15 12:27:06
你检查过你的模板吗?我也遇到了类似的问题,发现问题出在我的链接中的href。
<a href=#"></a>这导致路由器在将URL临时切换为我真正想要的URL后,将我发送回root。
发布于 2012-08-10 05:10:42
我不确定这是否能解决任何问题,但是您配置路由器的方式很奇怪。我不认为有必要使用Marionette的appRouter,因为您没有使用它的特性,并且我不会在initialize方法中配置路由。以这种方式配置路由器更像是“骨干网”:
app.utils.AppRouter = Backbone.Router.extend({
routes: {
"": "home",
"account": "account"
},
home: function(){
console.log("In home!");
app.layout.content.show(new app.views.BrowseRestaurantsLayout());
},
account: function(){
console.log("In account!");
app.layout.content.show(new app.views.AccountView());
}
});您定义路由的方式可能与此有关。
https://stackoverflow.com/questions/11890839
复制相似问题