簡體   English   中英

使用ember.js路由名稱

[英]Routing names with ember.js

我有這樣的路由器

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.show作為顯示資源的名稱,然后將其引用為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");
    });
});

由於資源名稱嵌套在發票資源中,因此它會自動在資源名稱前加上前綴。 對?

是的,嵌套資源可以堆疊其名稱,並且您應該能夠引用帶點表示法的嵌套路由。

但是,您將想做更多類似的事情:

    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");
    });

因為您的更新操作依賴於提供給放映路線的對象。

基本上,將依賴於嵌套元素或父路由中使用的資源子集的嵌套元素定義為資源映射。 葉子節點可以定義為基本路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM