2013-05-21 18 views
1

我有一个现有的Ember应用,效果很好。我需要添加一个新的子路由到应用程序,以允许用户查看其他信息。我目前的路线是这样的:向现有的Ember.js应用添加新路由,需要输入

Social.Router.map(function() { 
    this.resource('accounts', { path: '/accounts' }, function(){ 
     this.resource('account', { path: ':account_id'}); 
    }); 
}); 

使用下列URL

#/accounts/56/ 

我想补充的路线是这样的:

#/accounts/56/interactions 

所以我增加了一个嵌套的路线一样所以:

Social.Router.map(function() { 
    this.resource('accounts', { path: '/accounts' }, function(){ 
     this.resource('account', { path: ':account_id'}, function(){ 
      this.route('interactions', { path: '/interactions'}); 
     }); 
    }); 

});

但是,当这条路被访问,我得到以下错误:

Uncaught Error: assertion failed: The route interactions was not found core.libs.js:2236 
Uncaught Error: You cannot modify child views while in the inBuffer state core.libs.js:19298 

所以我还添加了一个空InteractionsRoute但是这并没有解决这个问题:

Social.InteractionsRoute = Ember.Route.extend(); 

有没有人对输入什么可能会出错?

另外我想添加一个按钮来,看起来像这样的接口:

{{#linkTo "interactions"}}@ Interactions{{/linkTo}} 
+1

你没有在/之前的交互路线尝试它:{path:'interactions'}? – daniatic

回答

1

尝试分裂出从个人记录视图列表。

Social.Router.map(function() { 
    this.resource('accounts'); 
    this.resource('account', { path: '/accounts/:account_id' }, function() { 
    this.route('interactions'); 
    }); 
}); 

您的交互路由名称应该是这样的:

Social.AccountInteractionsRoute = Ember.Route.extend(); 

从表上http://emberjs.com/guides/routing/defining-your-routes/

如果一切都失败了,你可能只是避免嵌套的资源和定义每个路径路线。

Social.Router.map(function() { 
    this.resource('accounts'); 
    this.resource('account', { path: '/accounts/:account_id' }); 
    this.resource('account-interactions', { path: '/accounts/:account_id/interactions' }); 
}); 
2
Social.Router.map(function() { 
    this.resource('accounts', { path: '/accounts' }, function(){ 
     this.resource('account', { path: ':account_id'}, function(){ 
      this.route('interactions', { path: '/interactions'}); 
     }); 
    }); 

}); 

象这样的URL相互作用是#/相互作用

但是你想这样:#/占/ 56 /相互作用 因此,你需要删除前面的斜杠的路径挂钩交互,否则你会指出这条路由将从根访问。

Social.Router.map(function() { 
    this.resource('accounts', { path: '/accounts' }, function(){ 
     this.resource('account', { path: ':account_id'}, function(){ 
      this.route('interactions', { path: 'interactions'}); 
     }); 
    }); 

}); 

顺便说一句,如果你没有声明一个路径挂钩,URL将和路由名一样。所以你也可以使用这个:

Social.Router.map(function() { 
    this.resource('accounts', function(){ 
     this.resource('account', { path: ':account_id'}, function(){ 
      this.route('interactions'); 
     }); 
    }); 

});