[英]EmberJS: force transition to parent route
我有兩條路線:一條名為parent
的主路線和一條名為parent.child
的子路線。 當在parent.child
發生某些事情時(我們稱之為X ),我想轉換到parent
,但由於技術上我們已經在那里,Ember 什么都不做。
// 'parent.child' controller
this.transitionToRoute('parent');
所以我想知道是否有辦法強制這種“過渡”。 原因是parent
中有代碼需要在X發生后重新運行。
您可以在父路由上調用refresh
。
現在在你的父路由上調用一個動作的最簡單的方法是定義一個,然后在你的控制器上使用send
來讓動作冒泡。
所以你的父路線:
class ParentRoute extends Route {
@action
refreshParent() { // dont name it refresh because of the naming conflict
this.refresh();
}
}
和您的子控制器:
class ChildController extends Controller {
@action
refreshParentRoute() { // again, another name
// this will first look for a `refreshParent` action on this controller,
// then the `child` route and last the `parent` route.
this.send('refreshParent');
}
}
為了恢復我們的子路線,您可以致電
this.transitionToRoute('parent.index');
我不確定這個解決方案會在沒有看到你的應用程序的情況下解決你的問題,例如這可能不會在父路由中重新運行鈎子,你可能需要將它們移動到routes/parent/index
或重新設計如何那些鈎子起作用了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.