Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor iron router的正确语法';什么路线?_Meteor_Iron Router - Fatal编程技术网

Meteor iron router的正确语法';什么路线?

Meteor iron router的正确语法';什么路线?,meteor,iron-router,Meteor,Iron Router,我在Meteor JS应用程序中为我的iron路由器签出路由提供了以下代码。我正在尝试将不推荐使用的Router.map转换为新的Router.route语法,但很难使onBeforeAction和onAfterAction正常工作。以下代码块的正确Router.route语法是什么 Router.map(function () { // sign-out the user then redirect them to the home page this.route('signOut'

我在Meteor JS应用程序中为我的iron路由器签出路由提供了以下代码。我正在尝试将不推荐使用的Router.map转换为新的Router.route语法,但很难使onBeforeAction和onAfterAction正常工作。以下代码块的正确Router.route语法是什么

Router.map(function () {

  // sign-out the user then redirect them to the home page
  this.route('signOut', {
    path: '/sign-out',
    onBeforeAction: function () {
      if (Meteor.userId()) {
        Meteor.logout()
      }
      this.next();
    },
    onAfterAction: function () {
      this.redirect('/');
    }
  });

});
我认为应该添加waitOn函数,因为如果不提前订阅,一开始可能不会有Meteor.user()对象

Router.route('/sign-out', function() {
//here you put things you wanna render, it's empty since you just want to logout and redirect
}, {
    name: 'signOut',
    onBeforeAction: function () {
      if (Meteor.userId()) {
        Meteor.logout()
      }
      this.next();
    },
    onAfterAction: function () {
      Router.go('/');
    }
});