流星v 1.0和Iron:Router [英] Meteor v 1.0 and Iron:Router
问题描述
自从将Meteor升级到1.0版之后,是否还有其他人从Iron-Router收到以下错误?
Is anyone else getting the following error from Iron-Router since upgrading Meteor to version 1.0?
如果您知道如何解决此问题,请在此处发布.
Please post here if you know how to resolve this issue.
路由分配从未呈现.您是否忘了在
onBeforeAction
中调用this.next()
?
Router.map(function () {
Router.route('profileShow', {
waitOn: function () {
if (Meteor.user()) {
Meteor.subscribe('userData');
} else {
this.next();
}
},
data: function () {
if (Meteor.user()) {
return {profile: Meteor.user().profile};
}
}
});
});
推荐答案
最新版本的Iron Router进行了向后兼容.迁移指南说:
There was a non backwards-compatible change in the newest version of Iron Router. The migration guide says:
onRun
和onBeforeAction
挂钩现在要求您调用this.next()
,并且不再使用pause()
自变量.因此,默认行为是相反的.例如,如果您有:
onRun
andonBeforeAction
hooks now require you to callthis.next()
, and no longer take apause()
argument. So the default behaviour is reversed. For example, if you had:
Router.onBeforeAction(function(pause) {
if (! Meteor.userId()) {
this.render('login');
pause();
}
});
您需要将其更新为
Router.onBeforeAction(function() {
if (! Meteor.userId()) {
this.render('login');
} else {
this.next();
}
});
对于您而言,按书上的解决方法是在onBeforeAction
的末尾添加this.next()
.但是,您应该使用waitOn
:
In your case, the by-the-book fix would be to add this.next()
at the end of onBeforeAction
. However, you should rather use waitOn
:
waitOn: function () {
return Meteor.subscribe("userData");
}
这样,您可以设置loadingTemplate
,该loadingTemplate
将在加载userData
订阅时显示.
That way, you can set a loadingTemplate
which will appear while the userData
subscription is loading.
这篇关于流星v 1.0和Iron:Router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!