[英]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.