Redirecting not logged-in users with iron-router… Again

前端 未结 5 1917
梦毁少年i
梦毁少年i 2020-12-13 15:05

I am fighting with the common need for redirecting a user to a login page if he is not logged-in (Meteor v0.8.0 on Windows 7).

There are several similar questions on

5条回答
  •  庸人自扰
    2020-12-13 15:13

    On Meteor 0.8.3 for me works:

    Router.onBeforeAction(function () { 
      if (_.include(['formLogin'], this.route.name)){
        return;
      }
    
      if (!Meteor.userId()) {
        this.redirect('formLogin');
        return;
      }
    
    });
    

提交回复
热议问题