【问题标题】:Redirect Doesn't Allow Me To Go To Other Links重定向不允许我转到其他链接
【发布时间】:2015-11-22 08:02:00
【问题描述】:

我正在尝试使用以下代码进行登录重定向:

Router.onBeforeAction(function () {
    if (!Meteor.user() && !Meteor.loggingIn()) {
        this.next();
    } else {
        // required by Iron to process the route handler
        this.redirect('/map');
        this.next();
    }
});

但是,当我登录并成功将我重定向到 /maps 时,我无法单击导航栏上的任何链接。该链接工作正常,但是,当我单击它们时,它只会将我重定向回 /map。

我们将不胜感激!

另外,这里是github链接:

https://github.com/Aggr0vatE/testbasichelp

【问题讨论】:

  • 我可能弄错了,但我觉得每次加载页面时您的代码总是在运行,因此如果您已登录,您会被重定向到 /map。
  • 是的,这就是我现在的想法。问题只是如何解决它。

标签: redirect meteor iron-router meteor-accounts


【解决方案1】:

这个呢:

Router.route('/login',
              { name: 'login' });

var requireLogin = function(){
  if (! Meteor.user() ) {
    this.redirect('login');
  } else {
    this.next();
  }
}

Router.onBeforeAction(requireLogin, {except: ['login']});

【讨论】:

  • 我应该为“somepage”重定向什么?
  • 那是它可以工作的页面。例如,您可以有一个“管理员”,您希望在其中完成检查。我已经更新了我的答案,希望它更清楚。
  • 好的,所以 somepage 就像我的代码将被检查的地方
  • 但是如果我没有这样的页面,我只是删除代码吗? (对不起,铁路由器新手>.
  • 试试这个:Router.onBeforeAction(checkLogin, {except: ['login']}); - 答案已编辑
猜你喜欢
  • 2018-10-25
  • 1970-01-01
  • 1970-01-01
  • 2016-04-13
  • 1970-01-01
  • 2012-11-18
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
相关资源
最近更新 更多