Durandal 2.0 に同梱されている「samples」プロジェクトは、ルーターをカスタマイズせずに目的を達成する方法の例です。以下の例はそのプロジェクトのものです (また、「子」ルーターの使用方法も示しています)。「makeRelative」の呼び出しの moduleId パラメーターとルート構成を組み合わせて、必要なフォルダー構造を提供する方法に注目してください。
app/ko/index.js
define(['plugins/router', 'knockout'], function(router, ko) {
var childRouter = router.createChildRouter()
.makeRelative({
moduleId:'ko',
fromParent:true
}).map([
{ route: '', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro' },
{ route: 'helloWorld', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro', nav: 5},
{ route: 'clickCounter', moduleId: 'clickCounter/index', title: 'Click Counter', type: 'intro', nav: 4},
{ route: 'simpleList', moduleId: 'simpleList/index', title: 'Simple List', type: 'intro', nav: 3 },
{ route: 'betterList', moduleId: 'betterList/index', title: 'Better List', type: 'intro', nav: 2},
{ route: 'controlTypes', moduleId: 'controlTypes/index', title: 'Control Types', type: 'intro', nav: 1 },
{ route: 'collections', moduleId: 'collections/index', title: 'Collection', type: 'intro' , nav: 99 },
{ route: 'pagedGrid', moduleId: 'pagedGrid/index', title: 'Paged Grid', type: 'intro', nav: 98 },
{ route: 'animatedTrans', moduleId: 'animatedTrans/index', title: 'Animated Transition', type: 'intro', nav: true },
{ route: 'contactsEditor', moduleId: 'contactsEditor/index', title: 'Contacts Editor', type: 'detailed', nav: true },
{ route: 'gridEditor', moduleId: 'gridEditor/index', title: 'Grid Editor', type: 'detailed', nav: true },
{ route: 'shoppingCart', moduleId: 'shoppingCart/index', title: 'Shopping Cart', type: 'detailed', nav: true },
{ route: 'twitterClient', moduleId: 'twitterClient/index', title: 'Twitter Client', type: 'detailed', nav: 1}
])
.buildNavigationModel();
return {
router: childRouter,
introSamples: ko.computed(function() {
return ko.utils.arrayFilter(childRouter.navigationModel(), function(route) {
return route.type == 'intro';
});
}),
detailedSamples: ko.computed(function() {
return ko.utils.arrayFilter(childRouter.navigationModel(), function(route) {
return route.type == 'detailed';
});
})
};
});