2014-11-20 10 views
0

내 문제는 두 개의 유사한 경로가 있으며 첫 번째 라우터가 내 구독을 기다리고 전체 템플릿을 렌더링하지만 두 번째 것은 즉시로드가없고 렌더링 된 데이터가 오류를 일으키는 것입니다. (아직 구독 된 컬렉션이 없기 때문에). 여기에 제 코드를 붙여 넣습니다. 템플릿과 데이터가 전달 되었기 때문에 두 번째 코드는 다릅니다.하지만 나머지 코드는 실제로 동일합니다. 철분 라우팅으로 시작한 것일까 요, 누군가 실수가 어디인지 말할 수 있을까요?라우터가 구독을 기다리지 않습니다.

Router.map(function() { 
     this.route('/', { 
      onBeforeAction: function() { 
       if (Meteor.user()) { 
        if (Meteor.user().firstLogin) 
         this.render("firstLogin"); 
        else 
         Router.go('/news'); 
       } else { 
        this.render("start"); 
       } 
      }, 
      waitOn: function() { 
       return Meteor.subscribe('allUsers'); 
      }, 
      onAfterAction: function() { 
       document.title = "someTitle"; 
      }, 
      loadingTemplate: "loading", 
     }); 
     this.route('users',{ 
      path:'/user/:_id', 
      layoutTemplate: 'secondLayout', 
      yieldTemplates: { 
       'template1': {to: 'center' }, 
       'template2': {to: 'top' }, 
       'template3': {to: 'left' }, 
       'template4': {to: 'right' }, 
      }, 
      waitOn: function(){ 
       return Meteor.subscribe("allUsers"); 
      }, 
      data: function(){ 
       return Meteor.users.findOne({_id:String(this.params._id)}); 
      }, 
      loadingTemplate: "loading", 
     }); 
    }); 

답변

1

lagacy에서 철제 라우터를 사용하고 있습니다. 니가 방금 시작했다면. 새 API를 사용하는 것이 좋습니다. 이 경우에는 완료 구독을 확인 this.ready()를 사용하거나하지

다음은 official guide

Router.route('/post/:_id', function() { 
    // add the subscription handle to our waitlist 
    this.wait(Meteor.subscribe('item', this.params._id)); 

    // this.ready() is true if all items in the wait list are ready 

    if (this.ready()) { 
    this.render(); 
    } else { 
    this.render('Loading'); 
    } 
}); 
의 예입니다
관련 문제