Meteor.js - Check logged in status before render

白昼怎懂夜的黑 提交于 2019-12-23 10:06:29

问题


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...

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']});

Hope this helps.


回答1:


Using fast-render might be a solution. Just run

mrt add fast-render

Check this great article on this topic.



来源:https://stackoverflow.com/questions/23139627/meteor-js-check-logged-in-status-before-render

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!