Ember-Router:如何在Ember 1.0-rc2中的运行时添加路由? [英] Ember-Router: How to add a route in run-time in Ember 1.0-rc2?
问题描述
在Ember 1.0-rc2中填充的新的 Ember.Router
中,是否可以在运行时添加路由?
目前没有一种支持的方法来执行此操作。 App.Router.map
调用由此代码的第235-247行处理: https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/ system / router.js
Ember.Router.reopenClass({
map:function(callback) {
var router = this.router = new Router();
var dsl = Ember.RouterDSL.map(function(){
this.resource('application' {path:/},function(){
callback.call(this);
})
});
router.map(dsl。 generate());
返回路由器;
}
地图被覆盖每次调用 Router.map
,因为前一次调用 Router.map
的回调不会持久存在。 p>
修改
无论好是坏,我有一个l请求改变行为以允许多次调用 App.Router.map
。我们会看看会发生什么。您可以在这里查看 https://github.com/emberjs/ember.js/pull/2485
另一个编辑
我已经写了一个要点做我的拉请求在用户的地方。这将让您在运行时映射路由。只需添加此代码,然后使用我定义的方法将您的调用替换为 App.Router.map
。
https://gist.github.com/grep-awesome/5406461
答案更改编辑
根据此拉请求,您现在可以调用 map
多次。 https://github.com/emberjs/ember.js/pull/2892
In the new Ember.Router
that shipts with Ember 1.0-rc2, is it possible add route in run-time?
There is not a supported method of doing this currently. The App.Router.map
call is handled by lines 235-247 of this code: https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/system/router.js
Ember.Router.reopenClass({
map: function(callback) {
var router = this.router = new Router();
var dsl = Ember.RouterDSL.map(function() {
this.resource('application', { path: "/" }, function() {
callback.call(this);
})
});
router.map(dsl.generate());
return router;
}
The map is overwritten every time you call Router.map
as the callback for the previous call to Router.map
is not persisted.
Edit
For better or worse, I've got a pull request in to alter the behavior to allow multiple calls to App.Router.map
. We'll see what happens. You can follow here https://github.com/emberjs/ember.js/pull/2485
Another Edit
I've written a gist to do what my pull request does in userland. This will let you map routes at runtime. Just add this code and then replace your calls to App.Router.map
with the method that I've defined
https://gist.github.com/grep-awesome/5406461
Answer Changing Edit
As of this pull request, you may now call map
multiple times. https://github.com/emberjs/ember.js/pull/2892
这篇关于Ember-Router:如何在Ember 1.0-rc2中的运行时添加路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!