【问题标题】:iron:router redirect not admin user铁:路由器重定向不是管理员用户
【发布时间】:2017-04-26 17:40:58
【问题描述】:

我想阻止某些用户输入特定的路线。我看过未登录用户的示例:

Router.onBeforeAction
(
    function () 
    {
        if (!Meteor.userId())
            this.redirect('/');
        else
            this.next();
    }
);

但是当我尝试时

Router.onBeforeAction
(
    function () 
    {
        if ( !isadmin( Meteor.userId() ) && Router.current().route.getName()=='admin' )
            this.redirect('/');
        else
            this.next();
    }
);

我收到下一条消息

iron_core.js?hash 路由调度从未渲染。你忘了 在 onBeforeAction 中调用 this.next()?

【问题讨论】:

    标签: javascript meteor iron-router


    【解决方案1】:

    尝试了类似的方法并成功了

    Template.admin.onRendered(function() {
       if ( !isadmin( Meteor.userId() ) )
       {
            Router.go('/');
       }
    });
    

    【讨论】:

      【解决方案2】:

      给你:

      Router.route('/your-url',{
          name:'routeName',
          onBeforeAction:function(){
              if(checkSomething){
                  //check passed, continue routing
                  this.next();
              } else {
                  //check failed, redirect.
                  Router.go('/not-authorized');
              }
          },
      
          action: function(){
               this.render('templateName');
          }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-29
        • 2020-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-24
        • 2021-03-24
        • 1970-01-01
        相关资源
        最近更新 更多