【问题标题】:How to build nested routes with ember.js that don't require all arguments?如何使用不需要所有参数的 ember.js 构建嵌套路由?
【发布时间】:2012-09-17 05:38:14
【问题描述】:

我有一个嵌套的路由结构,它允许分页/排序/搜索,这实际上会以某种方式调整 ArrayController。我对当前实现的问题是,一切都需要得到一个有效的页面来呈现。

http://localhost:8000/#/page/1/sort/username/search/dave

如果我只通过页面,我会收到错误

未捕获的错误:断言失败:找不到路径状态

我是否在嵌套路由中遗漏了某些内容,或者我是否需要将排序/搜索标记为可选?

PersonApp.Router = Ember.Router.create({
  root: Ember.Route.extend({
    index: Ember.Route.extend({
      route: '/',
      connectOutlets: function(router) {
        router.get('applicationController').connectOutlet('person', router.get('store').findAll(PersonApp.Person));
      },
      paginated: Ember.Route.extend({
        route: '/page',
        index: Ember.Route.extend({
          route: '/:page_id',
          connectOutlets: function(router, context) {
            console.log("here with page id " + context.page_id);
            router.get('personController').set('selectedPage', context.page_id);
          },
          exit: function(router) {
            router.get('personController').set('selectedPage', undefined);
          },
          sorted: Ember.Route.extend({
            route: '/sort',
            index: Ember.Route.extend({
              route: '/:column',
              connectOutlets: function(router, context) {
                console.log("SORTING " + context.column);
              },
              search: Ember.Route.extend({
                route: '/search',
                index: Ember.Route.extend({
                  route: '/:term',
                  connectOutlets: function(router, context) {
                    console.log("SEARCHING " + context.term);
                  }
                })
              })
            })
          })
        })
      })
    })
  })
});

【问题讨论】:

    标签: ember.js ember-old-router


    【解决方案1】:

    Emberjs 路由器只允许路由到叶节点,因此您必须通过在每个路由中添加虚拟“/”路由来使每个节点成为叶节点。以下问题与您的问题相似,您可以查看这些问题。 Why does Ember Router only allow navigating to leaf routes?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多