嵌套路由器回到父级

nested router going back to parent

我有这样的嵌套路由器设置:

this.resource('companies', function() {
    this.resource('company', {path:':company_id'}, function() {
        this.resource('employees', {path:'employees/:company_id'});
    });
});

当我点击 link 到公司然后 link 到员工时,没问题。除非我先转到不同的公司(id),如果我再次点击link到同一家公司,它不会显示公司。

所以基本上 1st 我去 /companies,它列出了公司,每个公司都有两个 links,一个给 /companies/1,另一个给 /companies/1/employees/1 ,如果我移动到 /companies/1/employees/1,然后返回到 /companies/1,它将不再呈现,除非我先转到 /companies/2,然后移动到 /companies/1 才会出现。然后,如果我在同一家公司 "id" 路径上,则重复该过程。

我已将其设置为公司和员工使用同一个插座,除此之外一切正常。

我的两个 link 我在模板中为每个项目设置如下:

{{#link-to 'company' this}}View Details: {{name}}{{/link-to}}
{{#link-to 'employees' id}}Employees{{/link-to}}

我不确定问题出在哪里,因为我是 Ember.js 的新手并且正在试验。感谢您的回复。

您不需要将 company.id 再次传递给您的嵌套路由,因为它是嵌套的,这意味着父模型已经解析,并且您可以使用 modelFor 访问它在您的员工路线内:

this.resource('companies', function() {
    this.resource('company', {path:':company_id'}, function() {
        this.resource('employees');
    });
});

// routes/employees.js

export default Ember.Route.extend({
  model: function() {
    var company = this.modelFor('company');

    return Ember.$.getJSON(employees_url + '?company=' + company.get('id'));
  }
});