【问题标题】:Proper syntax for iron-router's Router.route?Iron-router 的 Router.route 的正确语法?
【发布时间】:2015-01-02 14:24:08
【问题描述】:

我在 Meteor JS 应用程序中为我的 Iron-router signOut 路由提供了以下代码。我正在尝试将已弃用的 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('/');
    }
  });

});

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:
    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('/');
        }
    });
    

    而且我认为你应该添加 waitOn 函数,因为如果没有提前订阅,一开始可能没有 Meteor.user() 对象

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 2014-01-04
      相关资源
      最近更新 更多