I am trying to configure the router to allow one model for multiple views.
It is a 'profile' module so I have a top level router like so:
.map([{ route: ['profile*details', ''], moduleId: 'myprofile', title: 'Your Profile', hash:'#profile', nav: false } ])
And in the myprofile.js module I have the child router:
define(['services/unitofwork', 'services/logger', 'durandal/system', 'durandal/activator', 'viewmodels/profile', 'plugins/router', 'durandal/app', 'services/errorhandler'],
function (unitofwork, logger, system, activator, Profile, router, app, errorhandler) {
var MyProfile = function () {
this.router = router.createChildRouter()
.makeRelative({
moduleId: 'my',
fromParent: true
}).map([
{ route: ['details'], moduleId: 'details', title: 'Details', type: 'intro', nav: true },
{ route: 'search', moduleId: 'jobsearch', title: 'Job Postings', type: 'intro', nav: true },
{ route: 'resume', moduleId: 'resume', title: 'Resume', type: 'intro', nav: true },
{ route: 'account', moduleId: 'account', title: 'Subscription', type: 'intro', nav: true }
]).buildNavigationModel();
}
return MyProfile;
});
I was of the understanding that if I declared the main module with a splat route (profile*details), and that module returned a childrouter on the router property that defined the child-inner routes, that then I could maintain use of the child module to compose with each inner view.
Basically I want to use the viewmodels/myprofile.js module with the
views/my/details.html
views/my/resume.html
etcetera.
Using the unitofwork with Breeze, this pattern would enable me to enforce save checking on deactivate of each subview but without reloading the entire profile again.
It seems that the canReuseForRoute property could be of use, but I thought that it was not necessary given http://durandaljs.com/documentation/Using-The-Router.html - Module Reuse --
Consider the scenario where a history change causes a navigation that results in the same module as is already active and being viewed. Normally, even though the module is the same type, it will be discarded and a new instance created. There are two exceptions to this:
If the module has a child router associated with it. The instance will be kept. If the module has a special callback implemented, called canReuseForRoute, this function will be called allowing the developer to determine if the module should be discarded or not.
Am I missing something? Is it possible to achieve this?
Thanks.