Meteor JS: Flow-Router – Excelente way to create routes in your Meteor application

Flow-Router

https://github.com/kadirahq/flow-router

https://kadira.io/academy/meteor-routing-guide/content/introduction-to-flow-router

https://atmospherejs.com/meteorhacks/flow-router


meteor add meteorhacks:flow-router

FlowRouter is a very simple router for Meteor. It is focused only on routing for client-side apps and does not handle rendering itself.

How to use ?

FlowRouter.route('/perfil',{
   subscriptions: function(params, queryParams) {
      {{ ... PUT HERE YOUR SUBSCRITIONS, NECESSARY COLLECTIONS ... }} 
      {{ EVERY THING YOU PUT HERE GO TO YOUR MINIMONGO }} 
   },
   action: function(params) {
      {{ HERE CALL YOUR ROUTE }}
   }
})

Example :

FlowRouter.route('/perfil',{
   subscriptions: function(params, queryParams) {
      this.register('perfil', Meteor.subscribe('CurrentUser')); 
      this.register('clients', Meteor.subscribe('Clients'));
   },
   action: function(params) {
      if(Meteor.user()) {
         FlowLayout.render('Layout', {main: "Perfil"}); 
      }else{
         FlowRouter.go('/login');
      }
   }
})

WHERE

It’s my route : http://localhost:3000/perfil

/perfil

My subscriptions : ( collections )

CurrentUser and Clients

Look the publish.js file :

Meteor.publish('Clients',function(){
    Meteor.users.find({roles: PERFIL.CLIENT},{sort:{name: -1}});
});

Perfil is the template :

<template name="Perfil">
    {...}
</template>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s