【问题标题】:Meteor : redirect if user didn't create pageMeteor:如果用户没有创建页面,则重定向
【发布时间】:2016-04-21 15:31:06
【问题描述】:

在 Meteor 中,我有一个产品编辑页面。我只希望创建产品的用户看到该页面。否则你会被重定向。

有没有办法只用铁路由器做这个重定向? 如果没有,我会采取任何解决方案。

router.js

var OnBeforeActions;
OnBeforeActions = {
    ownerRequired: function(pause){
      if(!Meteor.userId()){
        Router.go('home');
      }else if(Meteor.userId()._id != ....SOMETHING?....){
        Router.go('home');
      }else{
        this.next();
      }
    }
};

Router.onBeforeAction(OnBeforeActions.ownerRequired, {
    only: ['editProduct']
});


Router.route('/editProduct/:_id',{
  template: "editProduct",
  name: "editProduct",
  data: function(){
    return Products.findOne({_id: this.params._id});
  }
});

【问题讨论】:

  • 对于您的产品,您当前是否存储其创建者的用户 ID,例如 createdBy 属性?
  • 是的@williamli 我这样做

标签: javascript meteor iron-router meteor-blaze


【解决方案1】:

所以如果你想知道如何解决这个没有铁路由器。你可以做这样的事情。 (请注意,如果用户已登录,我已经使用 onBeforeAction 进行检查。)

Template.editProduct.onCreated(function(){
    if(this.data.user === Meteor.userId()){
    }else{
        Router.go('home');
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    相关资源
    最近更新 更多