Durandal 2 / activate a method that is called only once on the children's route

In the Durandal 2.x application, I have a view that needs to retrieve new data every time a user navigates to it. This view is served through a child router:

define(['plugins/router'], function(router) {
    var vm = {};

    vm.router = router.createChildRouter()
        .makeRelative({
            moduleId: 'viewmodels/cms',
            fromParent: true
        }).map([
            { route: ['inventory', ''], moduleId: 'inventory/overview', title: 'Inventory Management', nav: true }
        ]).buildNavigationModel();

    return vm;
});

I put the logic of data sampling by method activateinoverview.js

define(function(){
    var vm = {};

    vm.activate = function(){
       // fetch data here
    };

    return vm;
});

However, it activateis called only for the first time, when I go to this view, while for views on the main router, it is called every time activate.

I tried installing cacheViews: falseon the child router, but did not change anything.

I also realized that the method bindingon my viewmodel is called every time around like this:

  • activate , ?
  • , ?
  • - binding?
+4
1

. , dom.

Durandal Docs Hooking Lifecycle, , .

EDIT: , , "" , . , , , . , DOM . , , , , - , , , . UI.

, , , . , → -, :). , Knockout, , , , .

+1

All Articles