Flow router is not working as expected while page refresh


#1

Hello, In my app, there are currently three routes (like myDesign, setting, help). when I login (using accounts-ui), myDesign route is working but
when I go to setting or help route, and then refresh a page, again myDesign route is rendered .
Here is the code sample I am using when an user login successfully (via
accounts-ui) …

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

FlowRouter.route('/myDesign', {
    name: 'myDesign',
    action() {
        mount(Home, {
            main: ,
        });
    }
});

what I want is that, when I refresh a page only that page is render. For example When I refresh a page rendered on help route, then only help route page should be rendered not page at myDesign route.

Any clue or solution for this issue ? Answers are greatly appreciated.

Thanks.


#2

Hello, do you have your onLogin event wrapped in a specific template onRendered/onCreated method?

It’s quite possible if you do not that it could be causing the redirect on refresh.


#3

Every time you refresh the page you trigger all the app logic. More over it logging you again and then your Accounts.onLogin and FlowRouter.go are calling.

As far as I understand your case you need to show myDesign page only once after user is logged with login form. So you have not to use accounts-ui and do it manually. Just create a simple form w user and password/ When user submits the form you should log him with:

Meteor.loginWithPassword(username, password, (err) => {
  if (!err) {
   FlowRouter.go('/anywhere');
  }
});