Best Practices: routes without parameters


#1

I am building a charting-like application (working on website now, will follow with mobile app). My app is fairly well contained within one main template with two regions that will change within (one for a list of user selections, the other to display details on each one). I am currently using iron-router but have just one route for home and use template-level subscriptions.

There will never be an instance where someone can copy a URL and send to someone else (the only way to access any detail is through selections made within the app, user needs to be logged in), so I prefer not to write URLs with parameters. Instead, to change the view, I am just using Session to switch between each of three categories of selections, as follows:

Template.StudioHeader.events({
'click #studio-valuations': function () {
    var valueValuations = "Valuations";
    Session.set('sessionGallery', valueValuations);
},
'click #studio-companies': function () {
    var valueCompanies = "Companies";
    Session.set('sessionGallery', valueCompanies);
},
'click #studio-deals': function () {
    var valueDeals = "Deals";
    Session.set('sessionGallery', valueDeals);
}
});

Template.Dashboard.helpers({
gallery: function() {
    var valueGallery = Session.get('sessionGallery');
    switch (valueGallery) {
        case "Valuations":
            return Template.GalleryValuations;
            break;
        case "Companies":
            return Template.GalleryCompanies;
            break;
        case "Deals":
            return Template.GalleryDeals;
            break;
        default:
            return Template.GalleryValuations;
            break;
    }
}

});

The structure I am using now works fine EXCEPT for the fact that Session resets on browser refresh. If a user is looking at the Companies template and refreshes the browser, the Valuations template will re-render.

What are the best practices here?

  • Is there a way to use Session but maintain the same value on refresh?
  • OR is there a way to use a route but not display any parameters in the URL? I had originally used the structure outlined in Discover Meteor but I would like to avoid something like .com/Companies.

Thank you.


#2

well, you can always save the current query to collection on server and than load it when user refresh, or log in etc


#3

Thanks, I thought that might be a third option but just hadn’t seen any examples using a collection to direct workflow around an app, so was concerned it might not be a generally accepted practice.