2014-09-23 126 views
2

當使用鐵路路由器更改爲不同的模板(頁面)時,是否會自動取消訂閱不再需要的集合?下面的情形說明問題鐵路路由器流星自動退訂?

  1. 第一頁上,我們稱之爲Meteor.subscribe(文件ID)
  2. 鐵路由器更改爲2
  3. 頁第2頁上,我們稱之爲Meteor.subscribe(文件,ID2) ,第1步自動取消訂閱?
+0

是,流星會自動退訂從訂閱的反應計算了進去(這是典型的'鐵的情況:路由器'),因此創建類似於訂閱管理器的東西可以防止這種行爲,如果你需要的話。 https://meteorhacks.com/subscriptions-manager-is-here.html – saimeunt 2014-09-23 12:53:06

回答

1

在這裏看到: https://github.com/EventedMind/iron-router/issues/265

鐵路由器/流星可以實現這個要求: 如果使用Deps.autorun反應計算中調用Meteor.subscribe,例如,認購將自動當計算取消無效或停止;

如果你希望緩存一些認購的,看到這個優秀的包裝: https://meteorhacks.com/subscription-manager-for-iron-router.html

this.route('postPage', { 
    path: '/post/:_id', 
    template: 'postPage', 
    waitOn: function() { 
     return Meteor.subscribe('post', this.params._id); 
    }, 
    cache: 5, //cache 5 blog posts 
    expire: 3 //expire them if inactive for 3 minutes 
    }); 
0

如果您將句柄(或包含句柄的數組)返回到路由的waitOn函數中的訂閱,鐵路由器將爲您取消訂閱。