SlideShare a Scribd company logo
Best Practice Routing
in Meteor and beyond
(BLAZE) OPINIONATED
TALK AHEAD
One step back:
Meteor History
● designed for single page apps
● routing is not part of core
● no guidelines or best practices
Iron Router
● the community steps in
● designed for Meteor < 1.X
● one-stop-shop for multi page apps:
routing, subscriptions, rendering,
layout manager
https://github.com/iron-meteor/iron-router
Flow Router
● designed for Meteor > 1.X
● only routing!
● separate packages for rendering
etc.
https://github.com/kadirahq/flow-router
Best practice routing in Meteor.js and beyond
Different platforms,
different challenges
The role model: RAILS
● “core gem” of RAILS
● enforces the MVC pattern
● CRUD
● full stack approach
http://guides.rubyonrails.org/routing.html
Python unchained: Django
● processes HTTP requests
● maps URL patterns to
views (via functions)
● no pattern enforced
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Old to the new: PHP
http://programmers.stackexchange.com/questions/122190/..
… is designed to emulate the familiar MVC
pattern of frameworks like Ruby on Rails …
MVC for Node? Meet sails.js
Best practice routing in Meteor.js and beyond
● Meteor is not the best
MVC platform (yet)
● client-side routing
● Model-View-Presenter
pattern
Think different
http://blog.nodejitsu.com/scaling-isomorphic-javascript-code/
Route:
/apps/:appId/:section
Helper:
Templates['foo'].helpers({
"someData": function() {
var appId = Router.
current().params.appId;
return doSomething(appId);
}
});
When is the “someData”
helper run?
Whenever the route changes!
→ i.e. when :section changes
https://github.com/kadirahq/flow-router
Router.current() is evil
Iron Router - waitOn
● easy to understand and implement
● it works (magic)
● subscriptions on the route level
● blocks rendering
http://iron-meteor.github.io/iron-router/#the-waiton-option
Best practice routing in Meteor.js and beyond
Template Level Subscriptions
● the place to manage
subscriptions in Meteor > 1.X
● template lifetime ==
subscription lifetime
● templates are more reusable
Template.post
Template.post
Template.activities
Template.profile
Do I have to ...
● migrate my existing project to
FlowRouter?
● refactor a lot of code if I decide to
migrate?
● learn new concepts to use it?
● use FlowRouter for my next project?
no
yes
no
yes!
meteor add iron:router meteor add kadira:flow-router
meteor add kadira:blaze-layout
(meteor add kadira:react-layout)
How to get started
Router.route('/', function () {
this.layout('layout');
this.render('MyTemplate');
});
FlowRouter.route('/, {
action: function() {
BlazeLayout.render("layout",
{main: "MyTemplate"});
}
});
Route definitions
Router.onBeforeAction(function () {
console.log(“before action”);
});
Router.onAfterAction(function () {
console.log(“after action”);
});
FlowRouter.triggers.enter([function(context){
console.log(“before action”);
}]);
FlowRouter.triggers.exit([function(context){
console.log(“after action”);
}]);
Hooks
Template.blogPost.onCreated(function() {
var self = this;
self.autorun(function() {
var postId = FlowRouter.getParam('postId');
self.subscribe('singlePost', postId);
});
});
https://kadira.io/academy/meteor-routing-guide
Breaking changes:
subscriptions
Template.blogPost.helpers({
post: function() {
var postId = FlowRouter.getParam('postId');
var post = Posts.findOne({_id: postId}) || {};
return post;
}
});
https://kadira.io/academy/meteor-routing-guide
Helpers
<template name="blogPost">
<a href="/">Back</a>
{{#if Template.subscriptionsReady}}
{{#with post}}
<h3>{{title}}</h3>
<p>{{content}}</p>
{{/with}}
{{else}}
<p>Loading...</p>
{{/if}}
</template>
https://kadira.io/academy/meteor-routing-guide
Templates
https://github.com/kadirahq/flow-router
There is more to come
https://github.com/kadirahq/flow-router
Do it yourself today
https://github.com/meteorhacks/meteor-inject-initial
meteor add meteorhacks:inject-initial
Best practice routing in Meteor.js and beyond
faburem Fabian Kromer @faburem

More Related Content

PDF
Meteor iron:router
PPTX
ngNewRouter
PPTX
Angular js introduction
PPTX
Neoito — Routing and navigation in Angular
PDF
Workshop 13: AngularJS Parte II
PDF
Angular Extreme Performance - V2
PPTX
Creating custom aggregator
PPTX
Building a production ready meteor app
Meteor iron:router
ngNewRouter
Angular js introduction
Neoito — Routing and navigation in Angular
Workshop 13: AngularJS Parte II
Angular Extreme Performance - V2
Creating custom aggregator
Building a production ready meteor app

Similar to Best practice routing in Meteor.js and beyond (20)

PDF
El viaje de Angular1 a Angular2
PDF
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
PDF
How to plan and define your CI-CD pipeline
PDF
Front End Development for Back End Developers - UberConf 2017
PDF
Angular (v2 and up) - Morning to understand - Linagora
PDF
Front end microservices: architectures and solution
PPTX
PDF
Counterclockwise past present future
PDF
ngconf2015
PDF
PDF
Daniel Steigerwald: EsteJS - javascriptové aplikace robusně, modulárně a komf...
PDF
Slack in the Age of Prometheus
PDF
Cleaning up Sitecore Controllers
PDF
Jayway Web Tech Radar 2015
PPTX
Client Side Performance for Back End Developers - Cambridge .NET User Group -...
PDF
New power of Angular2 Router
PPTX
Angular or React
PPTX
Foster - Getting started with Angular
PDF
Catching-up web technologies - an endless story
PPTX
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
El viaje de Angular1 a Angular2
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
How to plan and define your CI-CD pipeline
Front End Development for Back End Developers - UberConf 2017
Angular (v2 and up) - Morning to understand - Linagora
Front end microservices: architectures and solution
Counterclockwise past present future
ngconf2015
Daniel Steigerwald: EsteJS - javascriptové aplikace robusně, modulárně a komf...
Slack in the Age of Prometheus
Cleaning up Sitecore Controllers
Jayway Web Tech Radar 2015
Client Side Performance for Back End Developers - Cambridge .NET User Group -...
New power of Angular2 Router
Angular or React
Foster - Getting started with Angular
Catching-up web technologies - an endless story
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
Ad

Recently uploaded (20)

PPTX
Mathew Digital SEO Checklist Guidlines 2025
PPTX
Internet___Basics___Styled_ presentation
PPTX
Digital Literacy And Online Safety on internet
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPT
250152213-Excitation-SystemWERRT (1).ppt
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPT
Ethics in Information System - Management Information System
PPTX
artificialintelligenceai1-copy-210604123353.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
E -tech empowerment technologies PowerPoint
PDF
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
Database Information System - Management Information System
PPT
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
Introduction to cybersecurity and digital nettiquette
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Mathew Digital SEO Checklist Guidlines 2025
Internet___Basics___Styled_ presentation
Digital Literacy And Online Safety on internet
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
250152213-Excitation-SystemWERRT (1).ppt
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Ethics in Information System - Management Information System
artificialintelligenceai1-copy-210604123353.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
SAP Ariba Sourcing PPT for learning material
Sims 4 Historia para lo sims 4 para jugar
E -tech empowerment technologies PowerPoint
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
presentation_pfe-universite-molay-seltan.pptx
Database Information System - Management Information System
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
Power Point - Lesson 3_2.pptx grad school presentation
Introduction to cybersecurity and digital nettiquette
SASE Traffic Flow - ZTNA Connector-1.pdf
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Ad

Best practice routing in Meteor.js and beyond

  • 1. Best Practice Routing in Meteor and beyond
  • 3. One step back: Meteor History ● designed for single page apps ● routing is not part of core ● no guidelines or best practices
  • 4. Iron Router ● the community steps in ● designed for Meteor < 1.X ● one-stop-shop for multi page apps: routing, subscriptions, rendering, layout manager https://github.com/iron-meteor/iron-router
  • 5. Flow Router ● designed for Meteor > 1.X ● only routing! ● separate packages for rendering etc. https://github.com/kadirahq/flow-router
  • 8. The role model: RAILS ● “core gem” of RAILS ● enforces the MVC pattern ● CRUD ● full stack approach http://guides.rubyonrails.org/routing.html
  • 9. Python unchained: Django ● processes HTTP requests ● maps URL patterns to views (via functions) ● no pattern enforced https://docs.djangoproject.com/en/1.8/topics/http/urls/
  • 10. Old to the new: PHP http://programmers.stackexchange.com/questions/122190/..
  • 11. … is designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails … MVC for Node? Meet sails.js
  • 13. ● Meteor is not the best MVC platform (yet) ● client-side routing ● Model-View-Presenter pattern Think different http://blog.nodejitsu.com/scaling-isomorphic-javascript-code/
  • 14. Route: /apps/:appId/:section Helper: Templates['foo'].helpers({ "someData": function() { var appId = Router. current().params.appId; return doSomething(appId); } }); When is the “someData” helper run? Whenever the route changes! → i.e. when :section changes https://github.com/kadirahq/flow-router Router.current() is evil
  • 15. Iron Router - waitOn ● easy to understand and implement ● it works (magic) ● subscriptions on the route level ● blocks rendering http://iron-meteor.github.io/iron-router/#the-waiton-option
  • 17. Template Level Subscriptions ● the place to manage subscriptions in Meteor > 1.X ● template lifetime == subscription lifetime ● templates are more reusable
  • 19. Do I have to ... ● migrate my existing project to FlowRouter? ● refactor a lot of code if I decide to migrate? ● learn new concepts to use it? ● use FlowRouter for my next project? no yes no yes!
  • 20. meteor add iron:router meteor add kadira:flow-router meteor add kadira:blaze-layout (meteor add kadira:react-layout) How to get started
  • 21. Router.route('/', function () { this.layout('layout'); this.render('MyTemplate'); }); FlowRouter.route('/, { action: function() { BlazeLayout.render("layout", {main: "MyTemplate"}); } }); Route definitions
  • 22. Router.onBeforeAction(function () { console.log(“before action”); }); Router.onAfterAction(function () { console.log(“after action”); }); FlowRouter.triggers.enter([function(context){ console.log(“before action”); }]); FlowRouter.triggers.exit([function(context){ console.log(“after action”); }]); Hooks
  • 23. Template.blogPost.onCreated(function() { var self = this; self.autorun(function() { var postId = FlowRouter.getParam('postId'); self.subscribe('singlePost', postId); }); }); https://kadira.io/academy/meteor-routing-guide Breaking changes: subscriptions
  • 24. Template.blogPost.helpers({ post: function() { var postId = FlowRouter.getParam('postId'); var post = Posts.findOne({_id: postId}) || {}; return post; } }); https://kadira.io/academy/meteor-routing-guide Helpers
  • 25. <template name="blogPost"> <a href="/">Back</a> {{#if Template.subscriptionsReady}} {{#with post}} <h3>{{title}}</h3> <p>{{content}}</p> {{/with}} {{else}} <p>Loading...</p> {{/if}} </template> https://kadira.io/academy/meteor-routing-guide Templates
  • 27. There is more to come https://github.com/kadirahq/flow-router
  • 28. Do it yourself today https://github.com/meteorhacks/meteor-inject-initial meteor add meteorhacks:inject-initial