如何在Iron Router blaze集成上正确替换this.stop()with pause()

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()

谢谢

and*_*ash 8

从我可以告诉暂停函数是你的钩子被调用的第一个参数.不是在任何地方的文档中,但这是我从代码中收集的,它似乎工作.

这是我使用的:

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)


Dav*_*ave 4

我在 Github 上开了一个关于这个问题的问题。这是我得到的回复:

哎呀我可能还没有改变重定向方法。只需使用 Router.go,因为它现在可以正常工作了。我会在下周某个时候改变这个。重定向或者欢迎 PR。如果您更改挂钩中的路由,控制器现在会自动停止。您可以通过调用作为参数传递给挂钩和操作函数的暂停方法来暂停当前运行。