A simple package for Meteor prototyping
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



This is a very simple Meteor package made to speed up prototyping by automatically adding Iron Router routes.

Note that as soon as you start adding your own routes, you'll probably want to remove it.



Add it with:

meteor add sacha:autorouter

The package works by automatically setting up a number of useful routes for you.


This route will look for a template named home and display it.


This route will look for a template named templateName. For example, the route /about will display the template named about. It's that simple :)


If the route segment happens to be the name of a collection, the package will additionally set the data context of the route, using an object of the same name as the collection.

So if you have a collection named posts (as in Posts = new Mongo.Collection("posts")), the context for the route /posts will be set to:

  posts: Posts.find()

Which then lets you do {{#each posts}}...{{/each}} in your posts template.


Finally, if you also add an id as a second parameter, Autorouter will look for a template named collectionName, except without the last letter. So posts becomes post, users becomes user, etc.

set the context to the result of Collection.findOne(id).

A Practical Example

For example, you could have a posts collection:

Posts = new Mongo.Collection("posts");

A posts template:

<template name="posts">
    {{#each posts}}
      <li><a href=/posts/{{_id}}>{{title}}</a></li>

A post template:

<template name="post">

And an about template:

<template name="about">
  <p>Lorem ipsum dolor sit amet.</p>

And Autorouter will do the rest!


Thanks to @dburles for his help improving and refactoring the code!