Giter Site home page Giter Site logo

autorouter's Introduction

Autorouter

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.

Demo

Usage

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.

/templateName

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

/collectionName

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.

/collectionName/id

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">
  <h1>Posts</h1>
  <ul>
    {{#each posts}}
      <li><a href=/posts/{{_id}}>{{title}}</a></li>
    {{/each}}
  </ul>
</template>

A post template:

<template name="post">
  <h1>{{title}}</h1>
  <p>{{body}}</p>
</template>

And an about template:

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

And Autorouter will do the rest!

Thanks

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

autorouter's People

Contributors

dburles avatar sachag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.