2
内未定义回报我在流星以下设置:Meteor.user()路由器
当用户点击URL根和未登录,我展示一个欢迎页面。
当用户点击根URL并登录时,我想重定向到用户的“东西”页面。
问题是,Meteor.user()在路由器内部是未定义的。
这种结构的正确方法是什么?
<body>
{{# if currentUser}}
{{> thing}}
{{else}}
{{> welcome}}
{{/if}}
</body>
var MyRouter = Backbone.Router.extend({
routes: {
"": "welcome",
"/things/:thingId": "thing"
},
welcome: function() {
var user = Meteor.user();
console.log(user); //undefined
// Redirect to user's thing
},
thing: function(thingId) {
Session.set("currentThingId", thingId);
}
});
嗨,是的,用户是绝对注册并登录(在Chrome控制台中确认)。 –