Meteor v 1.0 和 Iron:Router [英] Meteor v 1.0 and Iron:Router
问题描述
自从将 Meteor 升级到 1.0 版后,还有其他人从 Iron-Router 收到以下错误吗?
如果您知道如何解决此问题,请在此处发布.
<块引用>路由调度从未呈现.您是否忘记在 onBeforeAction
中调用 this.next()
?
Router.map(function () {Router.route('profileShow', {等待:函数(){如果(流星.用户()){Meteor.subscribe('userData');} 别的 {this.next();}},数据:函数(){如果(流星.用户()){返回 {profile: Meteor.user().profile};}}});});
在最新版本的 Iron Router 中有一个非向后兼容的变化.迁移指南说:
<块引用>onRun
和 onBeforeAction
钩子现在需要你调用 this.next()
,并且不再需要 pause()
参数.所以默认行为是相反的.例如,如果您有:
Router.onBeforeAction(function(pause) {如果 (!Meteor.userId()) {this.render('登录');暂停();}});
<块引用>
您需要将其更新为
Router.onBeforeAction(function() {如果 (!Meteor.userId()) {this.render('登录');} 别的 {this.next();}});
<小时>
在您的情况下,书本上的修复方法是在 onBeforeAction
的末尾添加 this.next()
.但是,您应该使用 waitOn
:
waitOn:函数(){return Meteor.subscribe("userData");}
这样,您可以设置一个 loadingTemplate
,它会在 userData
订阅加载时出现.
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.
Route dispatch never rendered. Did you forget to call
this.next()
in anonBeforeAction
?
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};
}
}
});
});
There was a non backwards-compatible change in the newest version of Iron Router. The migration guide says:
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();
}
});
You'll need to update it to
Router.onBeforeAction(function() {
if (! Meteor.userId()) {
this.render('login');
} else {
this.next();
}
});
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");
}
That way, you can set a loadingTemplate
which will appear while the userData
subscription is loading.
这篇关于Meteor v 1.0 和 Iron:Router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!