1

我已经设法让一个简单的路由器工作,甚至为我的子菜单创建了一个子路由器,但有一两件事我不确定它们为什么在那里。文档为您提供了基本的支持,然后您就可以自己动手了。

所以我从这里阅读文档:http:
//durandaljs.com/documentation/Using-The-Router.html

首先,提到了“splat”路线,但它并没有真正解释它们是什么或如何使用它。你得到的只是一个 JS 的示例,如果不展示它是如何使用的,那将毫无意义。我的假设是它们意味着某种在一条线上定义多条路线的通配符系统?虽然不完全确定。

其次,在定义子路由器时,他们在“type:'intro'”的路由上设置了一个属性。虽然没有提及原因,但它似乎只与子路由器有关。有谁知道这种类型指的是什么以及不同的值是什么?

总的来说,我对这个框架印象深刻。我已经设法让一个看起来非常复杂的 web 应用程序很快就完成了。只是现在我想更深入地了解一下,文档并没有涵盖那么多细节。

编辑
四处挖掘,我设法找到了更多关于 splat 路线的信息。它看起来像是从骨干网和其他人那里复制的概念。
http://backbonetutorials.com/what-is-a-router/

基本上,如果我映射路线“section/*details”,那么这条路线将匹配任何以 section/ 开头的路径,并且 / 之后的所有内容都将作为名为 details 的参数传递。我看到这对子路由器有什么用处,因为它将确保深度链接能够正常工作。我们要确保对 section/admin 的请求首先发送到父路由器(section/part),然后发送到子路由器(admin)。

虽然仍然没有得到这个类型参数。我在任何地方都找不到解释。

4

1 回答 1

5

看看以下示例。淘汰样本是您正在寻找的,因为它演示了典型的子路由器用例。

  1. http://durandaljs.com/documentation/Understanding-the-Samples.html
  2. http://durandaljs.com/samples.html#knockout-samples
  3. https://github.com/BlueSpire/Durandal/blob/master/platforms/HTML/Samples/app/shell.js
  4. https://github.com/BlueSpire/Durandal/blob/master/platforms/HTML/Samples/app/ko/index.js

type参数用于创建两组导航链接。这是通过ko.computed在.vmforeachview

ko/index.js

...
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';
    });
})
...

ko/index.html

<ul class="nav nav-list">
    <li class="nav-header">Basic Examples</li>

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

    <li class="nav-header">Detailed Examples</li>


    <!--ko foreach: detailedSamples-->
    <li data-bind="css: { active: isActive }">
        <a data-bind="attr: { href: hash }, text: title"></a>
    </li>
    <!--/ko-->
</ul>
于 2013-11-28T15:48:44.420 回答