2012-11-29 79 views
17

在流星中,我使用Backbone來爲我的應用中的不同頁面提供路由。我目前有一個配置文件和一個管理頁面。當我進入個人資料頁面時,它就會顯示出來,但是當我去管理時,Meteor會回到主頁面。作爲一個側面說明,如果任何人有一個更好的模式或Meteor網頁的最佳做法,可以隨意分享,因爲這是非常麻煩的。流星中的路由

我用下面的模板來決定顯示哪一頁:

<template name="root"> 
    {{> navbar}} 
    {{#if pageIs "profile"}} 
     {{> profile}} 
     {{else}}{{#if pageIs "administration"}} 
     {{> administration}} 
     {{else}} 
     {{> main_page}} 
     {{/if}} 
    {{/if}} 
</template> 

的pageIs方法如下:

Template.root.pageIs = function(page){ 
    console.log(Session.get('page')); 
    return page === Session.get('page'); 
} 

而在我的骨幹路由器,下面的代碼:

var ProtonRouter = Backbone.Router.extend({ 
    routes: { 
     "profile": "profile", 
     "admin": "administration", 
     "administration":"administration" 
    }, 
    profile: function() { 
     Session.set('page','profile'); 
    }, 
    administration: function(){ 
     Session.set('page', 'administraion'); 
    }, 
    mainPage: function(){ 
     Session.set('page',null); 
    } 
}); 

pageIs方法中的log語句會記錄幾次未定義的記錄,然後記錄corr ect頁面,甚至在管理上也是如此,但Meteor似乎無論如何都不會重新加載所選頁面,並且該模板仍然會碰到最後一個else語句。

回答

25

UPDATE:鐵路由器已被棄用,以支持流量路由器。將來有strong indications that Flow Router will be supported as part of core Meteor

https://github.com/meteorhacks/flow-router

過時:先前普遍使用的路由器是鐵路由器:

https://github.com/EventedMind/iron-router

在它的發行,鐵路由器相結合的努力我們兩個最廣泛的作者編號爲流星路由器(meteor-routermini-pages),並且是流量路由器之前事實上Meteor的offcial路由器。