【问题标题】:How to define a standard child route in the durandal sample application如何在 durandal 示例应用程序中定义标准子路由
【发布时间】:2013-10-17 09:55:15
【问题描述】:

当我在网址栏中输入时:

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

hello world 路线在左侧。当我点击它时,网址栏变为: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();

【问题讨论】:

    标签: durandal durandal-2.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

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

    【讨论】:

    • 谢谢,我看到了小提琴链接,并获得了你所完成的真正有帮助的源代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    相关资源
    最近更新 更多