使用流星和铁路由器登录后重定向 [英] Redirect after Login using Meteor and Iron Router

查看:60
本文介绍了使用流星和铁路由器登录后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Meteor中使用内置的loginButtons选项,并且我希望在用户登录后进行重定向.使用内置的Web代码段意味着我无法在Meteor.loginwithPassword中使用回调,并且我看不到Iron-Router内的任何钩子都可以进行重定向.

I'm using the built in loginButtons options with Meteor and I would like to redirect after a user logs in. Using the built in web snippets means I can't use the callback with Meteor.loginwithPassword and I can't see any hooks inside Iron-Router to do the redirect.

有什么建议吗?

推荐答案

流星渲染速度如此之快,以至于在定义用户之前就已经加载了页面.您需要使用Meteor.loggingIn()来解决登录过程中的情况.该代码对我有用:

Meteor often renders so quickly that the page is being loaded before the user has been defined. You need to use Meteor.loggingIn() to account for the situation in which you are in the process of logging in. This code works for me:

this.route('myAccount', {
  path: '/',
  onBeforeAction: function () {
    if (! Meteor.user()) {
      if (!Meteor.loggingIn()) Router.go('login');
    }
  }
}

这篇关于使用流星和铁路由器登录后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆