문제

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?

도움이 되었습니까?

해결책

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});
});

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top