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
Since meteor-router is list with atmosphere we can install it using the mrt add
command
mrt add router
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.
Lets create our home template.
client/views/pages/home.html
<template name="home">
<h1>Welcome Home</h1>
</template>
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>
Now if you visit http://localhost:3000/ you will see: