Ember.JS:没有名为blah的路由

Ember.JS:没有名为blah的路由,ember.js,Ember.js,我得到这个错误: Assertion Failed: You attempted to define a `{{link-to "companies.show"}}` but did not pass the parameters required for generating its dynamic segments. There is no route named companies.show 但是我在router.js中有这个路由,在我添加两个新路由以及一个用于编辑/添加记录的组件之前,

我得到这个错误:

Assertion Failed: You attempted to define a `{{link-to "companies.show"}}` but did not pass the parameters required for generating its dynamic segments. There is no route named companies.show
但是我在
router.js
中有这个路由,在我添加两个新路由以及一个用于编辑/添加记录的组件之前,它正在工作。但它现在确实不见了——我也可以直接导航到它。因此,我认为我的另一部分有一个错误,那就是我的路线

// router.js 
Router.map(function() {
  this.route('states');
  this.route('companyTypes');

  this.route('companies', function() {
    this.route('show', {path: '/:company_id'});
    this.route('new');
    this.route('edit', {path: '/:company_id'});
  });

  this.route('counties', {path : '/counties/:state'});
});

// routes/companies.js
export default Ember.Route.extend({
  model() {
    return this.get('store').findAll('company');
  }
});

// routes/companies/show.js
export default Ember.Route.extend({
  model(params) {
    return this.get('store').findRecord('company', params.company_id);
  }
});

我正在将
链接中的模型参数传递到
,并且显示路由有其模型挂钩。

好的,所以问题是我在router.js中复制了相同的路由

// router.js
this.route('companies', function() {
    this.route('show', {path: '/:company_id'});
    this.route('new');
    this.route('edit', {path: '/:company_id'});
  });
“显示”和“编辑”具有相同的路线:如果导航到
http://localhost:4200/companies/1
您应该去显示还是编辑?“编辑”将覆盖“显示”,因为它位于最后。编辑后移动显示:

// router.js
this.route('companies', function() {
    this.route('new');
    this.route('edit', {path: '/:company_id'});
    this.route('show', {path: '/:company_id'});
  });
“显示”开始工作,但“编辑”将中断

所以你需要这样做:

// router.js
this.route('companies', function() {
    this.route('new');
    this.route('edit', {path: '/edit/:company_id'});
    this.route('show', {path: '/:company_id'});
  });
您现在的路线是:

http://localhost:4200/companies/1
http://localhost:4200/companies/edit/1

仅供参考:传统的编辑路径是
/:company_id/edit
@dwenzel,您的来源是什么?我确实想遵循正确的余烬惯例走出家门。我所研究的一个示例项目有一个编辑,它按照我上面的方式进行编辑,但不能保证他们做得对。我认为这只是一个REST API约定,尽管我找不到具体的源代码。不过,这似乎合乎逻辑:通常URL就像一个嵌套的文件夹结构:
/companys/edit…
看起来像是你在编辑所有的公司,而
/companys/:company\u id/edit
看起来像是你在编辑特定的公司,这就是你想要的。我确实找到了一些例子:,@dwenzel,好的,我会买的。看起来像是一个特定于余烬(或者可能是一个通用的RESTish框架)的东西,而不是一个实际的REST东西。在REST中,您拥有相同的URI,并更改标题中“视图”或“编辑”的动词。