tmeasday / meteor-router

MIT License
366 stars 76 forks source link

Going directly to route doesn't set Session variable #143

Closed dennismonsewicz closed 10 years ago

dennismonsewicz commented 10 years ago

Here are my routes:

Meteor.Router.add({
  '/jobs/:page': function(page) {
    Session.set('page', page)
    return 'jobs';
  },
  '/industry/:name': {
    to: 'jobs', and: function(name) {
      Session.set('currentIndustry', name);
    }
  }
});

I am needing the Session of currentIndustry to filter my jobs array on the front-end

Template[templateName].helpers({
  selected: function(){
    return Session.get('perPage');
  },
  jobs: function() {
    var cursor, options = {};

    if(Session.get('currentIndustry')) {
      options.industry = Session.get('currentIndustry');
    }

    logger(Session.get('currentIndustry'));

    if(Session.get('currentMapArea')) {
      city = Cities.findOne(Session.get('currentMapArea'));
      address = city.city.toProperCase() + ", " + city.state;
      options.address = address;
    }

    return Pagination.collection(
      Jobs, 
      options, 
      {sort: { dateacquired: -1 }}, 
      {perPage: Session.get('perPage') || 10, currentPage: Session.get('page') || 1}
    );
  }
});

If I console.log(Session.get('currentIndustry')) in my jobs helper, it returns null

tmeasday commented 10 years ago

Does the and function run?

dennismonsewicz commented 10 years ago

Yes, it runs and returns the passed in :name

dennismonsewicz commented 10 years ago

@tmeasday I figured it out... I was setting the Session variable to null in a Meteor.startup function