如何为多个子视图定义路由

时间:2014-04-04 09:47:56

标签: durandal durandal-2.0 durandal-navigation

我正在使用durandal进行开发和应用。我的页面中有两个部分,带有不同的导航菜单。我正在使用合成来制作这些子视图。但我不确定如何为这些部分定义路线。

1 个答案:

答案 0 :(得分:0)

shell.js

 { route: 'work*details', moduleId: 'profile/index', title: 'Profil', nav: 1, hash: '#profil', authorize: ["User", "Administrator"] },

在子文件夹 index.js

var childRouter = router.createChildRouter()
        .makeRelative({
            moduleId: 'viewmodels/marketplace',
            fromParent: true
        }).map(userRoute[

            // put you sub nav here

            ]).buildNavigationModel();

    return {
        router: childRouter,
        work: ko.computed(function () {
            return ko.utils.arrayFilter(childRouter.navigationModel(), function (route) {
                return route.type == 'intro';
            });
        })
    };

标记

    <ul class="nav navbar-nav">

        <!--ko foreach: work-->
        <li data-bind="css: { active: isActive }">
            <a data-bind="attr: { href: hash }, text: title"></a>
        </li>
        <!--/ko-->

    </ul>

了解更多here