【问题标题】:Cannot transitionTo, the error "more context objects were passed than there are dynamic segments" is incorrect无法transitionTo,错误“传递的上下文对象多于动态段”不正确
【发布时间】:2019-01-25 20:29:21
【问题描述】:

我使用的是 Ember 3,但在使用带有动态分段的路由器服务时遇到问题。在我的组件中,我使用路由器服务来transitionTo单击子路由,但出现此错误:

错误:传递的上下文对象多于动态对象 路线段:data.images.image

这是在组件js中,我使用transitionTo并为一个动态段传递一个参数:

router: service(),
actions: {
    navToSubpage() {
        // this.image is a single Ember Data record/object
        this.router.transitionTo('data.images.image', this.image)
    }
},

这是来自我的路由器,它有一个带有一个动态段的嵌套路由:

Router.map(function() {
  this.route('data', function() {
    this.route('images', function() {
      this.route('image', {path: '/image_id'});
    });
  });
});

我做错了什么?在这种情况下,这个错误对我来说没有意义。

【问题讨论】:

    标签: ember.js ember.js-3


    【解决方案1】:

    我在路由器中缺少: 之前的image_id。因此路由器没有将image_id 识别为动态段,因此我的transitionTo 被解释为具有太多参数(1 而不是0)。它与路由器服务无关。

    这是更正后的路由器:

    Router.map(function() {
      this.route('data', function() {
        this.route('images', function() {
          this.route('image', {path: '/:image_id'});
        });
      });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      相关资源
      最近更新 更多