emilyKim
emilyKim

Reputation: 41

Flow router Meteor

I'm new with this framework. I want to use flow router as it is reactive. Before this I'm using iron router. Please someone show me how to change the code to flow router as flow router has no waitOn concept and onBeforeAction(replaced by triggersEnter). Your help and kindness really appreciated.

router.js

Router.route('/EditLokasi/:_id', {
    name: 'EditLokasi',
    template: 'EditLokasi',
    onBeforeAction: function(){
    var lokasiID = Lokasi.findOne({_id: this.params._id});
    this.render('EditLokasi',{data: lokasiID});      
    },
    waitOn: function(){
        if(Meteor.userId()){
            var userid = Meteor.user().username;
            return [ Meteor.subscribe('profiles', userid), Meteor.subscribe('login') ];
        }
    }
});

EditLokasi.js

Template.EditLokasi.helpers({
    lokasi: function(){
        return Lokasi.find({data:lokasiID});
    }
});

Upvotes: 0

Views: 278

Answers (1)

Thai Tran
Thai Tran

Reputation: 9935

You can use subscriptions to subscribe and then, on the template, check if the data is ready through subReady

FlowRouter.route('/login', {
    name: 'login',
    subscriptions: function() {
       var userid = Meteor.user().username;
       this.register('subscribe-to-profile',  Meteor.subscribe('profiles', userid));
       // do it the same for other subscribe

    },
    action(params) {
       var lokasiID = Lokasi.findOne({_id: this.params._id});
       BlazeLayout.render('EditLokasi', {data: lokasiID});
    }
});

And on your template

<template name="EditLokasi">
 {{# if helper_checkSubReady}}
 ......
 {{else}}
 loading....
 {{/if}}
</template>

helper_checkSubReady is a helper to check if the subscriptions are ready or not (check the link I mentioned above)

Upvotes: 1

Related Questions