问题
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