流星铁:路由器转换



我正在尝试使用iron:router实现页面之间的转换。我在css中定义了动画,现在我所需要的就是用iron:router调用它们。出于某种原因,以下代码:

animateContentOut = function() {
    $('#content').removeClass("animated fadeIn");
    return $('footer').addClass("hide");
}
fadeContentIn = function() {
    $('#content').addClass("animated fadeIn");
    return $('footer').removeClass("hide");
}
Router.onBeforeAction(animateContentOut);
Router.onAfterAction(fadeContentIn);

返回一个异常:

从未呈现路由调度。你忘了在中调用this.next()了吗一个onBeforeAction?

如Iron Router文档中所述,现在onBeforeActiononAfterAction回调都需要this.next()。https://github.com/iron-meteor/iron-router

因此,只需将这一行添加到fadeContentInanimateContentOut代码的末尾即可。

如果您已经登录,请尝试这样的

Router.onBeforeAction(function () {
    if (!Meteor.user()) {
      this.render('Login');
    } else { 
      this.next();
     }
});

最新更新