Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 转换触发两条路径_Ember.js_Ember Router - Fatal编程技术网

Ember.js 转换触发两条路径

Ember.js 转换触发两条路径,ember.js,ember-router,Ember.js,Ember Router,我的位置资源有两条路线:一条是概述“/places”,另一条是详细视图“/places/:id” this.resource('places', function () { this.resource('place', { path: '/:place_id' }, function () { }); }); 在我的应用程序控制器中,即在应用程序启动时,如果满足某些条件,我希望执行重定向。我通过 if (condition) { this.store.find('pla

我的位置资源有两条路线:一条是概述“/places”,另一条是详细视图“/places/:id”

this.resource('places', function () {
    this.resource('place', { path: '/:place_id' }, function () {
    });
});
在我的应用程序控制器中,即在应用程序启动时,如果满足某些条件,我希望执行重定向。我通过

if (condition) {
    this.store.find('place', 0).then(
        function (place) {
            self.transitionTo('place.index', place);
        }
    );
}
当我通过
log\u transitions:true
记录转换时,它会输出
转换到“places.place.index”
——看起来不错

但是,它会触发两个路由来呈现模板:PlacesRoute和PlaceRoute。由于两者都使用不同的出口来呈现其模板,因此我看到了两者的内容


如何防止这种行为?当我以后执行到另一个地方的转换时,一切都按照我的预期工作,即它只触发PlacesRoute(而不是PlaceRoute)

首先,我建议将'place'资源重命名为'places.place'(
this.resource('places.place',…)
this.route('place',…)
以获取最新版本的余烬)

第二,你想做什么?当余烬处理到子路由的转换时,它应该在层次结构中加载和呈现路由(应用程序路由->放置路由->放置路由,以防转换到
places.place
route)。如果路线已经呈现(呈现),则不会发生任何事情(例如:从地点id为1的
places.place
转换到地点id为2的
places.place
不会触发应用程序和地点路线的重新提交)


将子路由视为显示信息的渐进式规范:在
places
route中,用户可以看到位置列表和
places。place
route他可以看到位置列表和关于某个特定位置的信息。

Ok,感谢您清除了一些要点。但是按照预期工作的转换不是从/places/1到/places/2,而是从/somewheres到/places/1不会触发PlacesRoute(或者至少不会呈现模板)。我不是100%确定,但可能是因为子资源的声明方式错误。调试以拯救!:)好的,我想你的最后一句话是我的答案——我会试试别的:)