Router Smart Package

router is a Reactive Router for multipage apps

router uses the pagejs library to route urls to template. It also adds filtering which allows you to easily check permissions

  1. Since meteor-router is list with atmosphere we can install it using the mrt add command

     mrt add router
    
  2. Lets create our first route. Create a folder called client. Inside the folder create a file by the name routes.js

    client/routes.js

     Meteor.Router.add({
       '/': function () {
         console.log('loading home');
         return 'home';
       }
     });
    

    Notice that we return the string 'home'. The string returned is the name of the template that will be rendered when this route is called.

  3. Lets create our home template.

    client/views/pages/home.html

     <template name="home">
       <h1>Welcome Home</h1>
     </template>
    
  4. Now we need to tell Meteor where we want to render the template. Add the {{renderPage}} to our app.html template:

    client/views/app.html

     <head>
       <title>presentski</title>
     </head>
    
     <body>
       <div class="container" role="main">
         <div class="page-header">
           <a href="/">
             <h1>Presentski</h1>
           </a>
         </div>
         <div class="content">
           {{renderPage}}
         </div>
       </div>
     </body>
    
  5. Now if you visit http://localhost:3000/ you will see:

    Welcome Home

Resources

  • atmosphere - Meteorite Smart Package site
  • router - A Reactive Router for multipage apps
  • pagejs - Micro client-side router inspired by the Express router (~1200 bytes)

Comments