Meteor user()返回未定义的内部路由器

Meteor user()返回未定义的内部路由器,meteor,Meteor,我在Meteor中有以下设置: 当用户点击根URL并且没有登录时,我会显示一个欢迎页面 当用户点击根URL并登录时,我想重定向到用户的“thing”页面 问题是,Meteor.user()在路由器中未定义 正确的构造方法是什么 <body> {{# if currentUser}} {{> thing}} {{else}} {{> welcome}} {{/if}} </body> var MyRout

我在Meteor中有以下设置:

当用户点击根URL并且没有登录时,我会显示一个欢迎页面

当用户点击根URL并登录时,我想重定向到用户的“thing”页面

问题是,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);
    }
});

{{{#如果当前用户}}
{{>东西}
{{else}
{{>欢迎}
{{/if}
var MyRouter=Backbone.Router.extend({
路线:{
“:“欢迎”,
“/things/:thingId”:“thing”
},
欢迎:函数(){
var user=Meteor.user();
console.log(用户);//未定义
//重定向到用户的东西
},
事物:功能(thingId){
Session.set(“currentThingId”,thingId);
}
});

您确定当前用户已注册吗?调用Meteor.user()在客户端和服务器端都可用,因此您应该可以访问路由器文件中的当前用户实例。例如,我测试当前用户是否使用以下内容登录到我的路由器:

var requireLogin = function() { 
    if (! Meteor.user()) {
        if (Meteor.loggingIn())
            this.render(this.loadingTemplate);
        else
            this.render('accessDenied');
            this.stop();
        }
 }

Router.before(requireLogin, {only: 'postSubmit'})
检查mongo db中的服务器端:

$ meteor mongo
$ >db.users.find().count() // Should be greather than 0
客户端上的控件。例如,打开chrome控制台,只需输入:

Meteor.user();
null // Means user is currently not logged in 
     // otherwise you should receive a JSON object

您好,是的,用户已明确注册并登录(在Chrome控制台中确认)。