EmberJS网址格式

时间:2014-05-01 15:31:27

标签: javascript angularjs ember.js

在EmberJS中,您可以将URL路由构建为?:

http://www.mydomain.com/section/detail-123.html 123是变量

在angularJS中,URL中的分隔符必须是斜线,我想也是在Ember

是否存在可以使用此类网址的此类框架?

1 个答案:

答案 0 :(得分:2)

在ember中,可以通过组合serializeRoute类(http://emberjs.com/api/classes/Ember.Route.html#method_serialize)的Ember.Location钩子提供的可能性来实现此类网址,以根据需要修改网址并{{1} }(http://emberjs.com/api/classes/Ember.Location.html)删除散列标记并仅在URL中启用斜杠。

实施例,

http://emberjs.jsbin.com/jenabegi/1/

http://emberjs.jsbin.com/jenabegi/1/edit

App = Ember.Application.create();

App.Router.map(function() {
  /*the /jenabegi/1 part is added to make it function in jsbin*/
  this.route('index', {path: '/jenabegi/1/' });
  this.route("detail",{path:"/jenabegi/1/section/:detail_id"});
});
App.Router.reopen({
  location: 'history'
});

App.IndexRoute = Ember.Route.extend({
  redirect:function(){this.transitionTo("detail",{value:"123"});}
});

App.DetailRoute = Ember.Route.extend({
  serialize:function(model,params){
    return {"detail_id":"detail-"+model.value+".html"};
  }
});