Meteor.js-渲染前检查登录状态 [英] Meteor.js - Check logged in status before render

查看:59
本文介绍了Meteor.js-渲染前检查登录状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,让我们从我是Meteor的完整菜鸟开始.既然已经解决了,那就让问题开始吧...

First off lets just start with the fact that I am a complete noob with Meteor. Now that that is out of the way let the problem begin...

我有两页,位于'/'的初始页面和位于'/home'的主页.我正在使用铁路由器进行路由.现在,如果我尚未登录,并在启动页面上登录,则可以将其重定向到主页,这可以正常工作.现在,如果我关闭浏览器并重新打开并转到"/",它会加载几秒钟,然后就会意识到我实际上仍在登录,然后将我重定向到"/home".

I have two pages, a splash page at '/' and a home page at '/home'. I am using iron-router for the routing. Now If I am not logged in and on the splash page and login I have it redirecting to the home page this works. Now if I close my browser and reopen and goto the '/' it loads for a few seconds then realizes that I am actually still logged in and then redirects me to '/home'.

我的问题是,当我已经登录时,如何摆脱显示在"/"上的初始显示?我只想向未登录的人显示该页面.这是我路由器中的代码:

My question is how to I get rid of this initial showing on the '/' when I am already logged in? I only want to show that page to people not signed in. Here is the code that I have in my router:

    Router.configure({layoutTemplate: 'mainLayout'});

Router.map(function() {
  this.route('splash', {path: '/'});
  this.route('home');
});

var mustBeSignedIn = function(pause) {
  if (!(Meteor.user() || Meteor.loggingIn())) {
    Router.go('splash');
    pause();
  }
};

var goToDashboard = function(pause) {
  if (Meteor.user()) {
    Router.go('home');
    pause();
  }
};

Router.onBeforeAction(mustBeSignedIn, {except: ['splash']});
Router.onBeforeAction(goToDashboard, {only: ['splash']});

希望这会有所帮助.

推荐答案

使用fast-render可能是一种解决方案.刚运行

Using fast-render might be a solution. Just run

mrt add fast-render

在此主题上查看这篇很棒的文章.

这篇关于Meteor.js-渲染前检查登录状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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