FlowRouter refresh page always go on base url

Hi everyone,

I’m having an issue with my app : each time I refresh the page or do a document.location.reload(), it goes back to the home page, the base url, the '/'.
I’m using Flow Router, BlazeLayout and Meteor 1.4.1.2
I can give you my route file :

if (Meteor.isClient) {
	Accounts.onLogin(function(){
		FlowRouter.go('home');
	});

	Accounts.onLogout(function(){
		FlowRouter.go('login');
	});
};

FlowRouter.triggers.enter([function(context, redirect) {
	if(!Meteor.userId()) {
		FlowRouter.go('login');
	}
}]);

FlowRouter.route('/userSettings', {
	name: 'userSettings',
	action() {
		BlazeLayout.render('SettingsLayout', {main: 'userSettings'});
	},
});

FlowRouter.route('/migrationSettings', {
	name: 'migrationSettings',
	action() {
		BlazeLayout.render('SettingsLayout', {main: 'migrationSettings'});
	},
});

FlowRouter.route('/waves', {
	name: 'waves',
	action() {
		BlazeLayout.render('HomeLayout', {main: 'Labels'});
	},
});

FlowRouter.route('/createBatch/:step/:id', {
	name: 'createBatch',
	action() {
		BlazeLayout.render('HomeLayout', {main: 'CreateBatch'});
	},
});

FlowRouter.route('/createBatch/:step/', {
	name: 'createBatch',
	action() {
		BlazeLayout.render('HomeLayout', {main: 'CreateBatch'});
	},
});

FlowRouter.route('/', {
	name: 'home',
	action() {
		// if(Meteor.userId()) {
		// 	FlowRouter.go('/')
		// }
		BlazeLayout.render('HomeLayout', {main: 'Devices'});
	},
});	

FlowRouter.route('/login', {
	name: 'login',
	action() {
		BlazeLayout.render('loginPage');
	},
});

Thank you guys

Have you tried removing the Accounts.onLogin where you tell it to route home? Seems like the culprit. IIRC you log in when you reload the page.

Instead of having it there you could just put the route home in the callback of the actual login function of your login template code.

1 Like

Thank you so so much. It worked.
I owe you a beer :wink:

1 Like