In a Durandal 2.x app I have a view that needs to fetch new data every time the 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 have placed the data-fetching logic on the activate
method in overview.js
define(function(){
var vm = {};
vm.activate = function(){
// fetch data here
};
return vm;
});
However, activate
is only called the first time I navigate to that view, whereas for the views on the main router, activate
is called every time.
I have tried setting cacheViews: false
on the child router but that didn't change anything.
I have also realized that a binding
method on my viewmodel is called every time around so:
- How can I enforce
activate
to be called every time the user navigates to the view? - Is there a better hook to place my data fetching logic when I always want it to be refreshed?
- Alternatively, is there something inherently wrong with placing my activation logic on the
binding
method?
cacheViews
, setting it to eithertrue
orfalse
on both the main and child routers, but it made no difference – Sergi PapaseitalwaysTriggerAttach: true
on your child router composition binding? – Brett