Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create dynamic URL's with Meteor?

I'm new to web dev and was blown away by the demo on Meteor's site and would like to use it. I've only used Google App Engine so far and to handle a dynamic URL in the main class I would write something like this:

app = webapp2.WSGIApplication([('/[0-9]', HandlePost)], debug=True)

This would map any URL's with the numbers 0 through 9 at the end to a handler class that would load an HTML page with the appropriate data for a page using a templating engine such as handlebars.

How do I do something similar in Meteor?

like image 651
Zaheer Avatar asked Jul 25 '12 18:07

Zaheer


2 Answers

Use backbone's router, see: http://backbonejs.org/#Router-routes
For regexps like your example see: http://blog.rjzaworski.com/2011/12/regex-routing-with-backbone-js/
Try out the todo example on meteor, see the client/todo.js file:

////////// Tracking selected list in URL //////////

var TodosRouter = Backbone.Router.extend({
  routes: {
    "todo_list/:list_id": "main"
  },
  main: function (list_id) {
    Session.set("list_id", list_id);
    Session.set("tag_filter", null);
  },
  setList: function (list_id) {
    this.navigate("todo_list/"+list_id, true);
  }
});

Router = new TodosRouter;

Meteor.startup(function () {
  Backbone.history.start({pushState: true});
});
like image 69
TiansHUo Avatar answered Nov 15 '22 11:11

TiansHUo


An alternative to using Backbone's router is Meteor Router. I can't vouch for it, only having just discovered it myself but it looks fairly full-featured.

like image 34
fractious Avatar answered Nov 15 '22 12:11

fractious