0

sorry, I'm new to webdev and Meteor and I'm not quite sure of the correct terminology. I am using Meteor-Router to create routes in my Meteor app.

I'm trying to create a test restaurant app, so an entry in my database might be:

name: "Kentucky Fried Chicken"
type: "Fast Food"

On the main page of the app, you see a list of restaurants. But the user can click on any item on that list to get to a more detailed page.

I would rather that the urls don't look like:

/restaurant/123

but more so like:

/fast-food/kentucky-fried-chicken
/japanese/sushi-r-us
/italian/some-italian-restaurant-name

Is this possible to do with Meteor & Meteor-Router? Thank you!

Btw, right now my routes are very simple:

Meteor.Router.add({
  '/': 'home',
  '/admin': 'admin',
  '/403': 'unauthorized'
});
4

2 回答 2

2

您可以使用比现在使用的更复杂的路由,如下所示:

Meteor.Router.add({
  '/:type/:restaurant': function(type, restaurantName) {
    var restaurant = Retaurants.findOne({type: type, name: restaurantName});
    Session.set('restaurantFromUrl', restaurant);
    // Now your restaurant is in the "restaurantFromUrl" Session
    return 'restaurantPage';
  }
});

/:type 和 /:re​​staurant 将被传递到回调中,并且是您在 URL 中设置的任何值。哦,您可能还想添加 /show-restaurant/type/name/,否则所有匹配模式“/whatever/url”的 url(未在其他路线中设置)都将尝试获取餐厅.

你需要知道的一切都在这里:https ://github.com/tmeasday/meteor-router

哦,这只是一个例子。尚未对其进行测试,但它应该可以工作。

于 2013-06-14T06:26:45.313 回答
0

目前大多数人使用的 Meteor 路由包是:Iron Router

于 2014-05-21T07:25:03.273 回答