【发布时间】:2014-12-02 17:19:24
【问题描述】:
我是 Marionette 的新手(虽然不是 Backbone),并决定使用它来管理我的路由。假设我有以下情况:
var AppRouterController = {
//Route to the homepage
home: function() {
//Unload the existing route, and load this one instead
},
//Route to a user profile page
user: function() {
//Unload the existing route, and load this one instead
},
//Route to a list of tasks or something
tasks: function() {
//Unload the existing route, and load this one instead
},
};
var TheRouter = new Marionette.AppRouter({
controller: new AppRouterController(),
appRoutes: {
"home": "home",
"user/:id": "user",
"tasks/:date": "tasks"
}
});
我希望我的应用动态加载每条新路由,并从 DOM 中完全删除其前身(可能通过动画,至少在一段时间内,它们将共享屏幕空间)。我可以看到我的应用有两个区域:“导航栏”和“内容”(来自给定路线的信息被呈现的区域”):
<html>
<body>
<section region="navbar"></section>
<section region="content" id="home|user|tasks|whateverRoute"></section>
</body>
</html>
所以,我的 DOM 主体总是有两个孩子:导航栏区域部分和内容区域部分,无论 Marionette 中的当前活动路线是什么。在 Marionette 中管理此过程的最佳方法是什么?我的意思是,只在需要时抓取特定路径中的模块(而不是在加载时抓取它们),创建一个新的“内容”区域,并以平滑的方式替换现有的“内容”区域。
【问题讨论】:
标签: javascript backbone.js routes marionette