2014-12-25 11 views
2

Meteor에 로그인했는지 여부에 따라 레이아웃을 어떻게 결정합니까? 내가 사용자가 Meteor로 로그인했는지 확인하십시오.

Router.map(function() { 
    this.configure({ 
    layoutTemplate: Meteor.userId() ? "appLayout" : "startLayout", 
    }); 
}); 

을 시도

나는 오류가 Meteor.user() 언급 한 바와 같이 당신이 사용자로부터 데이터를 필요로하는 경우, 그렇지 않으면 Meteor.users.findOne({_id: this.userId})를 사용, 기능에서 사용할 수있는, 당신은 this.userId을 사용할 수 있습니다

Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions. 

답변

-2

오류를 얻을 수집.

또한, 다리미 라우터 구조는 here 새로운 문서

+1

'this.userId'는 로그인되어 있어도'undefined'입니다. 내 맵핑 또는 사용되지 않는 경로 구조입니까? http://eventedmind.github.io/ironrouter/#creating-route-controllers에 따르면 구조는 여전히 사용됩니다. 다른 구조를 사용하는 경우 각 경로의 이름을 지정하는 방법을 모르겠습니다. – Jamgreen

+0

컨트롤러는 동일하게 유지되지만 더 이상지도 기능이 없으며 해당 기능에 대해서는 전혀 알지 못합니다 (waitOn 등), http://eventedmind.github.io/iron-router/#route-parameters 각 경로를 작성하기 위해 http://eventedmind.github.io/ironrouter/#named-routes를 지정하십시오. – Sindis

+0

this.userId 라우트가 Meteor.user() 오브젝트보다 먼저 작성되기 때문에 정의되어 있지 않아야합니다. 따라서 this.userId는 다음과 같습니다. 페이지가로드되기 전에 호출됩니다. 어쩌면 그것을 함수로 묶어보세요. – Sindis

0

그것은 것입니다, 사용되지 않습니다 그 Meteor.user() 반환 undefined가 로그 아웃 않다면 그것은로드 및 null 인 경우에, 동일한 Meteor.userId()의 사실이다.

0
if(Meteor.userId(){ 
    layoutTemplate: "appLayout"; 
}else{ 
    layoutTemplate: "startLayout"; 
} 

너는 이와 비슷한 것을 시도 했습니까?