Search code examples
meteoriron-router

Is there a way to prevent the loadingTemplate from showing up on "fast" routes?


Most of the time, my search returns so fast that it's not worth flashing the loading template to the user...(in fact, it's distracting, as people are fine with a blank screen if the results are coming a split second later)...Is there any way to prevent the loading template from showing if the waitOn is only waiting for a short amount of time?

Here's my configuration

  Router.route('/search', {
    waitOn: function () {
      return searchSubsManager.subscribe("search", Session.get('searchString'));
    },
    action: function () {
      this.render('searchResults');
    }
  });

I saw that with this package: https://github.com/Multiply/iron-router-progress you can control whether it shows up for fast routes, but I don't need all that functionality, nor do I want the progress bar it provides... I'm just wondering if the basic iron router/ waitOn functionality can provide this ability.


Solution

  • There is not configuration to use on the waitOn function, but Why don't you create another layout template, and use it to show that fast routes?

    <template name="noLoading">
      {{> yield}}
    </template>
    
    Router.map(function () {
      this.route('fastRoutes', {
      path: '/someRoutes',
      template: 'myHomeTemplate',
      layoutTemplate: 'noLoading',
      });
    });
    

    Update

    or use the sacha:spin package and change the class name depending on the duration of the query.

    if(queryDuration){
     Meteor.Spinner.options = {
        className: 'none'
      }
    }else{
      Meteor.Spinner.options = {
        className: 'spinner'
      }
    }