Ember可选URL段

时间:2014-11-11 17:48:12

标签: javascript ember.js url-routing

Ember中有没有办法在网址中添加可选段?

这就是/:locale/reservations/:id中的:locale是可选的,以便/fr/reservations/12345/reservations/12345一样工作?

我当前的路由器如下所示:

App.Router.map ->
  @resource 'reservation', path: '/*locale/reservations/:id', ->
    @route('status', path: '/status')

1 个答案:

答案 0 :(得分:0)

点击此处emberjs using multiple paths / urls for one routeserialize尝试以下内容:

serialize: function(model, params) {
  var locale, id;

  if(model.locale)
    locale = model.locale;
  else
    locale = '';

  id  = model.id;
  return { locale: locale, id: id };
}