【问题标题】:this.redirect load only blank pagethis.redirect 只加载空白页
【发布时间】:2015-02-27 01:40:42
【问题描述】:

这段代码很好用

  {
        action: function() {
            this.render('userprofile');
        },
        onBeforeAction: function() {
                this.redirect('/mypage');
        }
    });

但是没有

{
    action: function() {
        this.render('userprofile');
    },
    onBeforeAction: function() {
        if (Meteor.user().profile.uname == this.params.uname) {
            this.redirect('/mypage');
            this.stop();
        } else {
            this.next()
        }
    }
});

if (Meteor.user().profile.uname == this.params.uname) {
      this.redirect('/mypage')
} else {
    this.next() 
}

如果你输入不正确的uname这个条件有效

 } else {
                this.next()
            }

如果是真的

if (Meteor.user().profile.uname == this.params.uname) {
                this.redirect('/mypage');
                this.stop();
            }

页面仅将链接从 /StevePi(正确的 unname)更改为 /mypage,但不渲染

我尝试使用Router.go()和其他方法,但没有帮助:(

【问题讨论】:

  • 为什么要调用 this.stop()?另外,您是否在验证 Meteor.user().profile.uname 实际上是在调用什么东西?您是否收到任何控制台错误?

标签: meteor iron-router


【解决方案1】:

我意识到情况就是这样(也许它会帮助某人):

Router.route('/:uname', function() {
if (Meteor.user().profile.uname == this.params.uname) {
    window.location.href = "/mypage"; <---------------------------------
} else {
    this.render('userprofile')
}
});

【讨论】:

    猜你喜欢
    • 2011-08-11
    • 1970-01-01
    • 2014-10-22
    • 2019-02-25
    • 1970-01-01
    • 2011-10-14
    • 2020-03-09
    • 2011-05-08
    • 1970-01-01
    相关资源
    最近更新 更多