我的router.js是否正确?

时间:2018-05-17 05:42:54

标签: ember.js ember-data ember-components

当我尝试在浏览器上访问我的路线UnrecognizedUrl时,我收到dashboard/posts/id/comments错误。以下是我的router.js我想询问我的路由器是wrong还是有人请告诉我正确的方法

this.route('dashboard', function() {
  this.route('posts', function() {
    this.route('show', { path: ':post_id' }, function() {
      this.route('comments', { path: ':post_id/comments'}, function() { });
    });
  });
});

但是,如果我将{{outlet}}放在我的资源文件app/pods/dashboard/posts/show/template.hbs上,那么当我将app/pods/dashboard/posts/show/comments/template.hbs更改为

时,它会显示我放在router.js上的内容
  this.route('dashboard', function() {
    this.route('posts', function() {
      this.route('show', { path: ':post_id' }, function() {
        this.route('comments');
      });
    });
  });

我的目标是,我希望在浏览器网址应为app/pods/dashboard/posts/show/comments/template.hbs的其他网页上显示dashboard/posts/id/comments的内容

1 个答案:

答案 0 :(得分:0)

应该是

this.route('dashboard', function() {
  this.route('routeA', function() {
    this.route('childRouteA', { path: '/:childRouteA_id' }, function() {
      this.route('childRouteAb');
    });
  });
});
  

例如:信息中心/路线A / id / childRouteAb

如果childRouteAb是动态ID,那么它应该是

this.route('dashboard', function() {
  this.route('routeA', function() {
    this.route('childRouteA', { path: '/:childRouteA_id' }, function() {
      this.route('childRouteAb', { path: '/:childRouteAb'});
    });
  });
});
  

例如:信息中心/ routeA / id / id2

如果你需要url在id之前指定id的类型,你可以这样做。

this.route('dashboard', function() {
  this.route('routeA', function() {
    this.route('childRouteA', { path: '/childRouteA/:childRouteA_id' }, function() {
      this.route('childRouteB', { path: '/childRouteB/:childRouteB_id'});
    });
  });
});
  

例如:信息中心/路线A / childRouteA / id1 / childRouteB / id2

相关问题