Add routing to Meteor JS

July 20, 2013

Reading time ~1 minute

Metor JS does not come with support for routing (i.e. having separate pages) out-of-the-box. But it is easy to add that using the router smart package.

Install the router smart package

Assuming that you have Meteorite installed. Just run:

mrt add router

Configure routes in your client JavaScript

Update your client JavaScript code to also contain the following:

* Routing
  '/example': 'my-example',
  '/': 'welcome',
  '*': '404'

Update your HTML template

Now, we do not want to render all templates every time the page is loaded. It’s easy to fix my updating your templates slightly with the renderPage function.

  <title>Example service</title>

<template name="menu">
  <div class="menu">
    <strong>Example Service</strong>
    <a href="/">Home</a>
    <a href="/example">Example page</a>

<template name="welcome">
  <p>This is the start page</p>

<template name="my-example">
  <h1>My example</h1>
  <p>This is an example page</p>

<template name="404">
  <h1>Oops, page not found</h1>
  <p>The page you were looking for has gone missing!</p>

More features available

This is just a basic example of how to use the router smart package. Check out the project’s webpage for detailed documentation.

Running vim-airline with Maximum Awesome

I use [Maximum Awesome]( when I code in [vim](, it's a great starting place...… Continue reading

Quicksort implementation in Python

Published on August 04, 2014

Fibonacci generator in Python

Published on August 04, 2014