1

我有这样的路由器

App.Router.map(function () {
    this.route("about");
    this.resource("invoices", { path: "/invoices" }, function () {
        this.resource("invoices.show", { path: "/:id" });
        this.resource("invoices.update", { path: "/:id/edit" });
        this.route("create");
    });
});

并生成指向各种路线和资源的链接,我有这个

<nav>
    {{#linkTo "invoices.index"}}Invoices{{/linkTo}}
    {{#linkTo "invoices.show" 1}}Invoice{{/linkTo}}
    {{#linkTo "invoices.create"}}New invoice{{/linkTo}}
</nav>

为什么我必须使用invoices.showshow 资源的名称,然后将其引用为,invoices.show但我可以将create其用于路由,然后将其引用为invoices.create

理想情况下,我的路由器是

App.Router.map(function () {
    this.route("about");
    this.resource("invoices", { path: "/invoices" }, function () {
        this.resource("show", { path: "/:id" });
        this.resource("update", { path: "/:id/edit" });
        this.route("create");
    });
});

并且它会自动为资源名称添加前缀,因为它们嵌套在发票资源中。正确的?

4

1 回答 1

1

是的,嵌套资源可以堆叠它们的名称,并且您应该能够使用点符号引用嵌套路由。

但是,您会想要做更多类似的事情:

    this.resource("invoices", { path: "/invoices" }, function () {
        // invoices.show
        this.resource("show", { path: "/:id" }, function() { 
             // invoices.show.update
             this.route("update", { path: "/edit" });
        });
        // invoices.create
        this.route("create");
    });

因为您的更新操作依赖于提供给 show 路由的对象。

基本上,依赖于相同资源或父路由中使用的资源子集的嵌套元素应定义为资源映射。叶节点可以定义为基本路由。

于 2013-03-06T01:28:28.593 回答