Ember,没有名为联系人的路由错误

Ember, There is no route named contact error

我是 Ember 的新手。我使用的是最新版本 2.6.2。我正在为一条路线而苦苦挣扎。当我转到联系人页面时,出现这样的错误 Error: There is no route named contact.

我的app/route.js

Router.map(function() {
  this.route('contacts', function() {
    this.route('show', { path: '/:contact_id' });
  });
});

我的 app/routes/联系人/index.js

export default Ember.Route.extend({
  model: function() {
    return this.store.findAll('contact');
  }
});

我的app/templates/contacts/index.hbs

<ul>
  {{#each model as |contact|}}
    <li>
      {{#link-to 'contact' contact}}
      {{contact.lastName}},
      {{contact.firstName}}
      {{/link-to}}
    </li>
  {{else}}
    <li>No contacts found.</li>
  {{/each}}
</ul>

我的app/models/contact.js

import DS from 'ember-data';

export default DS.Model.extend({
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  email: DS.attr('string'),
  title: DS.attr('string'),
  createdAt: DS.attr('date'),
  updatedAt: DS.attr('date')   
});

感谢您的帮助。

如果 link-to 链接到在您的路线中找不到的路线,您将收到该错误消息。

您在 router.js 中有两个命名路由 1. contacts 2. contacts.show

更改您的 app/templates/contacts/index.hbs 文件。

<ul>
  {{#each model as |contact|}}
    <li>
      {{#link-to 'contacts.show' contact}}
        {{contact.lastName}},
        {{contact.firstName}}
      {{/link-to}}
    </li>
  {{else}}
    <li>No contacts found.</li>
  {{/each}}
</ul>