How do I create dynamic URL's with Meteor?

元气小坏坏 提交于 2019-12-05 00:41:12

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/11656001/how-do-i-create-dynamic-urls-with-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!