【问题标题】:'match' syntax for nested routes in emberember 中嵌套路由的“匹配”语法
【发布时间】:2013-01-01 06:28:56
【问题描述】:

我的问题涉及不久前集成到主 ember.js 分支中的新路由机制。

在以下代码块中:

App.Router.map(function(match) {
  match("/comments").to("commentsIndex");
});

ember 路由器现在识别 cmets url,并通过“to”方法的第一个参数(在本例中为“cmetsIndex”)将路由处理程序映射到 cmetsIndexRoute。从这里您可以选择使用视图/模板/控制器的默认映射,或者覆盖它们。

但是在下面的嵌套路由中:

App.Router.map(function(match) {
  match("/posts").to("posts", function(match) {
    match("/").to("postsIndex");
    match("/:post_id").to("postShow");
  });
});

我现在不确定第一个匹配中“to”方法的第一个参数的作用。换句话说,我不确定下面大写参数的作用:

 match("/posts").to("POSTS", function(match) {

那个参数到底是做什么的?

【问题讨论】:

    标签: routing ember.js ember-router


    【解决方案1】:

    现在看来,这是嵌入“视图”的推荐方式。

    来自新的 Ember 文档:

    访问 /posts 略有不同。它将首先将帖子模板呈现到应用程序模板的出口中。然后,它将 postIndex 模板渲染到帖子模板的出口中。

    最后,访问 /posts/new 会首先渲染帖子模板, 然后将 newPost 模板渲染到它的插座中。

    http://emberjs.com/guides/routing/defining-your-routes/

    因此,.to("POSTS") 设置上下文以加载以下视图。

    【讨论】:

      猜你喜欢
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 2017-08-06
      • 2014-09-27
      相关资源
      最近更新 更多