Flow.router + user account don't work without Meteor.defer


#1

I have simple structure , / /login /main routes, when I signin, I must go to /main but routes go to /main and after redirect me to /

var mySubmitFunc = function(error, state){
  if (!error) {
    if (state === "signIn") {
        FlowRouter.go('main');
    }
  }
};
var myPostLogout = function(){
    FlowRouter.go('/login');
};
AccountsTemplates.configure({
    onLogoutHook: myPostLogout,
    onSubmitHook:mySubmitFunc,
});

and router

AccountsTemplates.configure({
    defaultTemplate: 'fullPageAtForm',
    defaultLayout: 'homeLayout',
    defaultLayoutRegions: {},
    defaultContentRegion: 'main'
});

AccountsTemplates.configureRoute('enrollAccount');

AccountsTemplates.configureRoute('signIn', {
    name: 'signin',
    path: '/login'
});

FlowRouter.route('/', {
    name: "home",
    action: function() {
        BlazeLayout.render('homeLayout',{main : 'home'});
      },

});

FlowRouter.route('/main', {
    name: "main",
    action: function() {
        BlazeLayout.render('mainLayout',{main : 'main'});
    },

});

but when I add this

 Meteor.defer(function( ) { 
        FlowRouter.go('main'); 
 });

All woks fine, so can some one explaine?


#2

I’m trying to understand, but I feel I’m missing something, if that’s all your code, the route ‘main’ should work properly


#3

Problem: When I login , I must redirect to /main but I am first redirect to main than to / , but with Meteor.defer all works fine


#4

Problem: When I login , I must redirect to /main but I am first redirect to main than to / , but with Meteor.defer all works fine

What ?


#5

How it must work (work like this with Meteor.defer)

  1. You login (write your mail, pasword) and click SUBMIT
  2. You redirected to /main
    How my code work without Meteor.defer
  3. You login
  4. Yoo redirected to /main
  5. Yoo redirected to /

#6

I don’t see any redirect to ‘home’ in your AccountsTemplates logic, so I guess that you are redirecting to ‘home’ from the route or the template

if your ‘main’ route is only this

FlowRouter.route('/main', {
    name: "main",
    action: function() {
        BlazeLayout.render('mainLayout',{main : 'main'});
    }
});

then the redirect is in your template


#7

In template I have only html no template helpers, events etc.