ser*_*rgi 8 meteor iron-router
当我将Iron Router升级到blaze集成分支时,我开始收到此警告:
"You called this.stop() inside a hook or your action function but you should use pause() now instead"
Run Code Online (Sandbox Code Playgroud)
Chrome控制台 - > iron-router.js:2104 - > client/route_controller.js:193 from package
代码在客户端:
Router.before(mustBeSignedIn, {except: ['userSignin', 'userSignup', 'home']});
var mustBeSignedIn = function () {
if (!Meteor.user()) {
// render the home template
this.redirect('home');
// stop the rest of the before hooks and the action function
this.stop();
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
我试着更换this.stop()
同:pause()
,Router.pause()
和this.pause()
,但仍然无法正常工作.另外我还没有在铁路由器包上找到暂停功能.
如何正确更换this.stop()
用pause()
?
谢谢
从我可以告诉暂停函数是你的钩子被调用的第一个参数.不是在任何地方的文档中,但这是我从代码中收集的,它似乎工作.
这是我使用的:
var subscribeAllPlanItems = function (pause) {
var planId = this.params._id;
this.subscribe('revenues', planId).wait();
this.subscribe('expenses', planId).wait();
};
var waitForSubscriptions = function (pause) {
if (this.ready()) { //all the subs have come in
//NProgress.done();
setPlan(this.params._id);
} else { //all subscriptions aren't yet ready, keep waiting
//NProgress.start();
pause();
}
};
Router.map(function () {
this.route('calendar', {
path: '/calendar/:_id',
template: 'calendar',
before: [
subscribeAllPlanItems,
waitForSubscriptions
],
});
//Other routes omitted
});
var requireLogin = function (pause) {
if (Meteor.loggingIn()) { //still logging in
pause();
}
if (!Meteor.user()) { //not logged in
this.render('signIn');
pause();
} else { //logged in, life is good
console.log("requireLogin: logged in");
}
};
//This enforces login for all pages except the below ones.
Router.before(requireLogin, {
except: ['landing', 'signUp', 'signIn', 'forgotPassword', 'resetPassword']
});
Run Code Online (Sandbox Code Playgroud)