我正在尝试将路由器配置为允许一个模型用于多个视图。
它是一个“配置文件”模块,所以我有一个像这样的顶级路由器:
.map([{ route: ['profile*details', ''], moduleId: 'myprofile', title: 'Your Profile', hash:'#profile', nav: false } ])
在 myprofile.js 模块中,我有子路由器:
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;
});
我的理解是,如果我使用 splat 路由(配置文件*详细信息)声明主模块,并且该模块在定义子内部路由的路由器属性上返回一个子路由器,那么我可以继续使用子模块与每个内部视图组成。
基本上我想将 viewmodels/myprofile.js 模块与
意见/我的/details.html
意见/我/resume.html
等等。
使用带有 Breeze 的 unitofwork,此模式将使我能够在每个子视图的停用时强制保存检查,但无需再次重新加载整个配置文件。
似乎 canReuseForRoute 属性可能有用,但我认为没有必要给http://durandaljs.com/documentation/Using-The-Router.html - 模块重用 -
考虑历史更改导致导航导致与已处于活动状态并正在查看的相同模块的情况。通常,即使模块是相同的类型,它也会被丢弃并创建一个新实例。这有两个例外:
如果模块有与之关联的子路由器。该实例将被保留。如果模块实现了一个特殊的回调,称为 canReuseForRoute,这个函数将被调用,允许开发者决定是否应该丢弃模块。
我错过了什么吗?有可能实现这一目标吗?
谢谢。