如何在durandal示例应用程序中定义标准子路由

时间:2013-10-09 20:40:14

标签: durandal durandal-2.0

当我进入网址栏时:

http://localhost:28905/#knockout-samples/

左侧是你好世界的路线。当我点击它时,网址栏会变为:http://localhost:28905/#knockout-samples/helloWorld

1。)如何立即加载http://localhost:28905/#knockout-samples/路线最初与子路线,所以当我加载淘汰样本时,我看到

this: http://localhost:28905/#knockout-samples/helloWorld and not 
this: http://localhost:28905/#knockout-samples/
来自durandaljs样本的

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: true},
            { route: 'clickCounter',    moduleId: 'clickCounter/index',     title: 'Click Counter',         type: 'intro',      nav: true},
            { route: 'simpleList',      moduleId: 'simpleList/index',       title: 'Simple List',           type: 'intro',      nav: true },
            { route: 'betterList',      moduleId: 'betterList/index',       title: 'Better List',           type: 'intro',      nav: true},
            { route: 'controlTypes',    moduleId: 'controlTypes/index',     title: 'Control Types',         type: 'intro',      nav: true },
            { route: 'collections',     moduleId: 'collections/index',      title: 'Collection',            type: 'intro' ,     nav: true },
            { route: 'pagedGrid',       moduleId: 'pagedGrid/index',        title: 'Paged Grid',            type: 'intro',      nav: true },
            { 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: true}
        ]).buildNavigationModel();

1 个答案:

答案 0 :(得分:1)

我已经使用guardRoute来完成顶级操作,例如http://dfiddle.github.io/dFiddle-2.0

// Redirecting from / to first route
    router.guardRoute = function(routeInfo, params, instance){
        if (params.fragment === ''){
            return routeInfo.router.routes[0].hash;
        }
        return true;
    };

https://github.com/dFiddle/dFiddle-2.0/blob/gh-pages/app/shell.js

类似的东西应该在二级导航上可行,但我没有测试过。

相关问题