Learn about the most popular Meteor router, designed to work in the browser and on the server.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
README.md

README.md

Class: Using Iron Router

Meteor


The iron:router package is often how people organize their Meteor applications. We'll start off by learning how to create dynamic paths and links. Then you'll see how the router uses the Blaze rendering engine to render dynamic layouts and regions. Then we'll study route controllers, including how to configure them, subscribe to and wait on data, and use hooks. Finally, you'll learn how to create RESTful server side routes.

What's in this class?

  • Introduction: Using Iron Router - In this class, we're going to take a practical look at how to use Iron Router to build a simple blog application. We'll look at client and server side routes, RESTful server side routes, the new contentFor and layout helpers and using Controllers properly. We'll also cover subscriptions and waitOn options.

  • Getting Started - The purpose of the router is to take a url and map it to some functionality in our application so we can do things like conditionally render a template. We start out by defining our first route by providing a path and a template or route function. We then use a layout and dynamically change the layout depending on the route.

  • Dynamic Paths - Dynamic paths are paths that have variables in them. In this video, we cover using dynamics and defining multiple routes. We interrogate the environment created by the Router.route() function and show the common mistake of ordering routes improperly. We end by showing the source code for Iron Router to see the types of dynamic paths it handles.

  • Link Helpers - Iron router comes with a helper that allow you to reference links by name and pass parameters like a query or hash string. This way, if your url scheme changes, your code isn't hardcoded to a specific url. This video shows you all the features behind the pathFor, urlFor and linkTo helpers that come with the new Iron Router.

  • Rendering with Data - There are multiple ways to set the data context for a page using Iron Router. We show how to define the data option function on a particular template or on the overall layout, which can be used or inherited by all the templates in it.

  • Layouts and Regions - Iron-layout allows layouts to have multiple dynamic regions by using the 'yield' keyword. We look at how to create these layouts and render content into their regions by using the 'contentFor' keyword.

  • Using Route Options - We explore providing additional options to our routes both locally and globally. We show how to use the Router.configure method to set the global data context for the page and use the lookOption function to look up options for a route. Routes can also guess the name of their template by the name of the route.

  • Subscribing to Data - In this video, we remove the autopublish package and instead show how to use Iron Router to manage your subscriptions based on the url or page you are on. To understand how a subscription works, we use the network tab to track data as it comes off the wire and use this.ready() to figure out when a subscription is ready.

  • Using the new waitOn Option - We show how to use the waitOn option to automatically add a loading hook for our subscriptions. We also show how to use the loadingTemplate option to define a custom loading template.

  • Hooks and Plugins - In this video, we cover all the hooks that now come with Iron Router including onRun, onRerun, onBeforeAction, onAfterAction and onStop. We look at what happens when you use the reactive onBeforeAction hook and why you need to call this.next() now. We then show you how to use the plugin interface to distribution and reuse functionality on specific routes.

  • Server Side Routes - Server side routing has gotten a complete refresh. Using Stripe as an example, we demonstrate how to create RESTful routes, use Connect middleware and use the bodyParser middleware to automatically parse POST data like JSON or XML.

  • Additional Resources - We showcase the new iron packages and good resources for further development with Iron Router.