我的应用程序上有以下Ember.Router:
App.Router = Ember.Router.extend({
location: 'hash',
rootElement: '#content',
enableLogging: true,
root: Ember.State.extend({
route: '/',
index: Ember.State.extend({
route: '/',
redirectsTo: 'main.welcome'
}),
main: Ember.State.extend({
route: '/main',
welcome: Ember.ViewState.extend({
route: '/welcome',
view: App.WelcomeView
})
})
})
});
我希望能够做的是在声明后通过添加到 App.Router 来添加其他路由(这是为了启用任意模块)。它是在 App.initialize() 之前还是之后完成并不重要。
下面是一个关于模块路由对象外观的示例:
Module.routes = Ember.State.extend({
route: '/module',
index: Ember.State.extend({
route: '/'
view: Module.IndexView
})
});
非常感谢对此事的任何帮助。
您可以提取要扩充的状态,以便以后可以重新打开它。
App = Ember.Application.create();
App.RootState = Em.State.extend({
index : Em.State.extend({
route : '/'
}),
main: Em.State.extend({
route : '/main',
index : Em.State.extend({
route : '/'
})
})
});
App.Router = Ember.Router.extend({
location : 'hash',
enableLogging : true,
root : App.RootState
});
// later...
App.RootState.reopen({
module: Em.State.extend({
route : '/module',
index : Em.State.extend({
route : '/'
})
})
});
App.initialize();
编辑:我在GitHub上使用最新版本