kakajansh / flowwy

Boilerplate app that integrates Meteor + Famo.us + FlowRouter
2 stars 2 forks source link

routes and passing data #4

Open dcsan opened 9 years ago

dcsan commented 9 years ago

I've progressed with the mock up a fair bit, deployed here http://famnav.meteor.com/stories

so question is how to use flowrouter to pass params into a specific view.

eg from http://famnav.meteor.com/stories

get to one specific story http://famnav.meteor.com/story/1

the relevant subscription would have to change and data for that view render.

kakajansh commented 9 years ago

I updated repo showing similar usage here

Shortly, after defining subs in router side

FlowRouter.route('/item/:id', {
    subscriptions: function(params) {
        this.handle = Meteor.subscribe('item', params.id);
        this.register('ItemSub', this.handle);
    },
    action: function(params, queryParams) {

    }
});

you can pass it directly to a blaze template.

Template.item.helpers({
    item: function() {
        return Items.findOne(FlowRouter.getParam('id'));
    }
});

or another way would be using famous surfaces.

// initialize
var surf = new Surface({ content: "loading" });

// update when data is available 
Tracker.autorun(function () {
    var item = Items.findOne(FlowRouter.getParam('id'));
    if (item) surf.setContent(item.text);
});