我是新手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身體總是有兩個孩子們:navbar區域部分和內容區域部分,無論Marionette中的當前活動路線如何,在Marionette中管理這個過程的最佳方式是什麼?我的意思是,只有當他們在特定的路線上抓取模塊時(而不是在負載時抓取它們),創建一個新的「內容」區域,並以平滑的方式替換現有的「內容」區域。
相應的HTML文件會是什麼?在加載任何東西之前,我是否已經需要爲我的區域準備好html,或者是否有一種首選的方式來創建它們,然後從一個空的物體開始? – AlexZ 2014-10-09 01:28:57
@AlexZ我已經更新了答案。 – 2014-10-09 06:43:43
啊,謝謝你。非常感激! – AlexZ 2014-10-09 16:53:28