次の Durandal子ルータープラグイン構成を使用すると、Durandal のライフサイクルで説明されてdetached
いるおよびactivate
イベントが取得されませんが、他のイベントは機能します。
これは、コンテナーchildRouter
のコンテンツを制御する単一ページのアプリケーションです。div
それぞれchildRouter
がモジュールに対応し、一度に 1 つだけを使用attached
し、他のものはdetached
.
アプリケーションはchildRouter
モジュールごとに個別のインスタンスを使用し、2 つのモジュール間のナビゲーションが発生するたびにdetached
およびイベントがトリガーされることを期待しています (つまり、 getおよびshould get )。activate
moduleOLD
detached
moduleNEW
attached
ドキュメントには、Durandal ライフサイクル イベントが自動的にトリガーされると記載されています。
緑で強調表示された行は、作成時に常に実行されます。
このようには機能しません。これは、次のことが原因である可能性があります。
- 子ルーターが相互にアタッチ/デタッチされていることを通知されていない(つまり、何らかのイベントにサブスクライブする必要がある)
- 親ルーターとは異なる動作をする子ルーター
detached
とactivate
. _
detached
およびactivate
のイベントをトリガーする方法はchildRouter
?
define([ 'durandal/app', 'plugins/router'], function(
app, router) {
var childRouter = router.createChildRouter();
childRouter.makeRelative({
moduleId : 'modules/moduleX/pages',
fromParent : true
});
childRouter.map([ {
route : [ '', 'grid' ],
moduleId : 'grid/index',
}, {
route : 'details/:id',
moduleId : 'details/index',
}, {
route : 'details/tabs/base',
moduleId : 'details/tabs/base',
} ]);
childRouter.buildNavigationModel();
childRouter.activate = function() {
console.log("activate");//DOESN'T WORK
};
childRouter.attached = function() {
console.log("attached");//WORKS
};
childRouter.compositionComplete = function() {
console.log("compositionComplete");//WORKS
};
childRouter.detached = function() {
console.log("detached");//DOESN'T WORK
};
return {
router : childRouter
};
});
出力 (エラーなし):
compositionComplete (gets called here too, when a route is first visited)
attached
compositionComplete