kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

triggersEntry not running jQuery on initial page load #631

Open deborah-ufw opened 8 years ago

deborah-ufw commented 8 years ago

I'm having some trouble with basics in FlowRouter. FlowRouter version is current in current version of Meteor.

On initial page load (or refresh), the triggersEntry function does print to the console log - but it does not run the jQuery. If user navigates to a different template in the same layout, then returns to this template, then the jQuery DOES run.

Why isn't the jQuery running on initial page load? What is the best way to make it do so?

FlowRouter.route( '/about', {
  action: function() {
    BlazeLayout.render( 'body-static', { 
      content:  'about',
    });
  },
  triggersEnter: [function() {
    $('a.about').addClass('active');
    console.log('entry trigger ran');
  }]
});
deborah-ufw commented 8 years ago

I've also tried a defer, but the behavior is still persisting. The jQuery runs on first load if I put it elsewhere (in the 'about' template itself, in my core UI js file... ).

Here is the defer, but it also did not work.

triggersEnter: [function() {
  Meteor.defer(() => {
    $('a.about').addClass('active');
    console.log('entry trigger ran');
  });
}]
rafa-munoz commented 8 years ago

What's your use case? Maybe you can do it in other way so that you don't need to use jQuery.

deborah-ufw commented 8 years ago

I did figure out another way (put it in the helper js), but it makes more sense to do it on the router since it is a TriggerEntry need. Using helpers instead is repetitive and hacky - I'd rather not scatter the same code everywhere.

FlowRouter's documentation shows jQuery being used on the Triggers for entry and exit (it does seem to work on exit). Is it a bug?


From: Rafa Muñoz notifications@github.com Sent: Tuesday, May 31, 2016 10:11 AM To: kadirahq/flow-router Cc: Deborah; Author Subject: Re: [kadirahq/flow-router] triggersEntry not running jQuery on initial page load (#631)

What's your use case? Maybe you can do it in other way so that you don't need to use jQuery.

You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/kadirahq/flow-router/issues/631#issuecomment-222738592, or mute the threadhttps://github.com/notifications/unsubscribe/AAXG59X2883UcK5krMHzkGn-gT9LVgUfks5qHF28gaJpZM4IiQsw.