我很难理解 Durandal 子路由器。我会感谢社区的一点帮助。我想在我的主选项卡路由器下创建一个子路由器。如果用户单击选项卡 B 而不是选项卡 A,我希望我的子路由器暴露。
_______
Tab A |Tab B |
_______________| |_______________
Button one Button Two
_______________________________________
Shell.js
define(['plugins/router'], function(router) {
return {
router: router,
activate: function() {
router.map([
{ route: ['', 'about'], title: 'About', moduleId: 'viewmodels/about', nav: true },
{ route: 'welcome*details', title: 'welcome', moduleId: 'viewmodels/welcome', nav: true, hash: '#welcome' }
]).buildNavigationModel();
return router.activate();
},
};
});
视图模型 1
欢迎.js
define(['durandal/system', 'plugins/router'], function (system, router) {
var vm = {
activate: activate,
childRouter: childRouter
};
function activate(){
system.log('*sol');
};
var childRouter = router.createChildRouter()
.makeRelative({
moduleId: 'marvins',
fromParent: true
}).map([
{ route: 'marvins', moduleId: 'viewmodels/marvins', title: 'marvins', nav: true },
]).buildNavigationModel();
return {
router: childRouter
};
return vm;
});
视图模型 2
马文斯.js
define(['durandal/system', 'plugins/router'], function (system, router) {
var vm = {
activate: activate
};
function activate() {
system.log('*dish');
};
return vm;
});
查看 1
欢迎.html
<div class="starsandbars">
<h1>Welcome to Durandal.js</h1>
<p>The most frustrating framework to learn</p>
<div data-bind="router: {transition: 'entrance'}"></div>
</div>
视图 2
马文斯.html
<ul>
<li>button one</li>
<li>button two</li>
</ul>
导航栏.html
<nav class="navbar" role="navigation">
<ul id="navright" class="nav nav-tabs" data-bind="foreach: router.navigationModel">
<li data-bind="css: { active: isActive }">
<a data-bind="attr: { href: hash },
css: { active: isActive }, text: title">
</a>
</li>
</ul>
</nav>