我从Ember.js开始,我有一个页面的三级路径。这是路由器地图的样子:
App.Router.map(function(){
this.resource('tests');
this.resource('create', function() {
this.resource('create.questions', {path: ':test_id' }, function() {
this.resource('create.questions.question', {path: ':question_id'});
});
});
});在我的CreateRoute中,我使用以下代码转换到创建/问题路由:
this.get('controller').transitionToRoute('create/questions', test);这很好,但是在我的CreateQuestionsRoute中,这段代码不起作用:
this.get('controller').transitionToRoute('create/questions/question', question);收到的错误:
Uncaught Error: Assertion Failed: Error: Assertion Failed: The route create/questions/question was not found 使用Chrome Ember检查插件,我可以看到路线如下:
CreateRoute
CreateQuestionsRoute
CreateQuestions.QuestionRoute这似乎是武断的行为。对于如何处理多个嵌套路由,没有多少指导。一些参考资料告诉我,我的路线图实际上应该是这样的:
App.Router.map(function(){
this.resource('tests');
this.resource('create', function() {
this.resource('questions', {path: ':test_id' }, function() {
this.resource('question', {path: ':question_id'});
});
});
});这样路由名称将自动嵌套(不需要点标记),但这不起作用。谁能用安伯的智慧为我亮点光?
发布于 2014-06-11 01:20:02
就这样吧:
App.Router.map(function(){
this.resource('tests');
this.resource('create', function() {
this.resource('questions', {path: ':test_id' }, function() {
this.resource('question', {path: ':question_id'});
});
});
});添加命名空间资源的唯一原因是资源不是唯一的。这意味着你可以使用任何一条路线
this.transitionTo('questions', model);
this.transitionTo('question', modelForQuestions, modelForQuestion);示例:http://emberjs.jsbin.com/OxIDiVU/636/edit
如果您希望保留您的命名空间,我将使用camelCase而不是点表示法,因为通常点表示当前作用域上的属性。
示例:http://emberjs.jsbin.com/OxIDiVU/637/edit
https://stackoverflow.com/questions/24153177
复制相似问题