[英]Routing names with ember.js
I have a router like this 我有这样的路由器
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");
});
});
and to generate links to the various routes and resources I have this 并生成指向各种路线和资源的链接
<nav>
{{#linkTo "invoices.index"}}Invoices{{/linkTo}}
{{#linkTo "invoices.show" 1}}Invoice{{/linkTo}}
{{#linkTo "invoices.create"}}New invoice{{/linkTo}}
</nav>
Why do I have to use invoices.show
for the name of the show resource and then reference it as invoices.show
but I can use create
for the route and then reference it as invoices.create
? 为什么我必须使用invoices.show
作为显示资源的名称,然后将其引用为invoices.show
但是我可以将create
用于路由,然后将其引用为invoices.create
?
Ideally my router would be 理想情况下,我的路由器是
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");
});
});
and it would auto-prefix the resource names since they are nested within the invoices resource. 由于资源名称嵌套在发票资源中,因此它会自动在资源名称前加上前缀。 Right? 对?
Yes, the nested resources can stack their names, and you should be able to reference a nested route with dot notation. 是的,嵌套资源可以堆叠其名称,并且您应该能够引用带点表示法的嵌套路由。
However, you will want to do something more like: 但是,您将想做更多类似的事情:
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");
});
since your update operation relies on the object supplied to the show route. 因为您的更新操作依赖于提供给放映路线的对象。
Basically nested elements that rely on the same, or a subset of resources used in a parent route should be defined as resource mappings. 基本上,将依赖于嵌套元素或父路由中使用的资源子集的嵌套元素定义为资源映射。 Leaf nodes can be defined as basic routes. 叶子节点可以定义为基本路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.