我有一个现有的Ember应用程序,效果很好。我需要向应用添加新的子路由,以允许用户查看其他信息。我目前的路线如下:
Social.Router.map(function() {
this.resource('accounts', { path: '/accounts' }, function(){
this.resource('account', { path: ':account_id'});
});
});
使用以下网址
#/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}}
答案 0 :(得分:2)
Social.Router.map(function() {
this.resource('accounts', { path: '/accounts' }, function(){
this.resource('account', { path: ':account_id'}, function(){
this.route('interactions', { path: '/interactions'});
});
});
});
像这样,互动的网址是#/ interactions
但你想要这个:#/ accounts / 56 / interaction 因此,您需要在交互的路径挂钩中删除前面的斜杠,否则您将指示将从根访问此路由。
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');
});
});
});
答案 1 :(得分: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' });
});