2017-04-05 43 views
2

我收到此錯誤路線: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這條路線,並在工作之前,我添加了兩個新航線與編輯組件沿/添加記錄。但現在確實沒有了 - 我也可以直接導航到它。所以我認爲我在我的另一部分有一個錯誤,就是在我的路線上d d。

// 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); 
    } 
}); 

我正在傳遞link-to中的模型參數,show路徑有它的模型掛鉤。

回答

2

好了,所以這個問題是我複製在router.js

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

都顯示和編輯有相同的路線相同的路線:如果您NAV至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 
+1

FYI:傳統的編輯路徑是'/:COMPANY_ID/edit' – dwenzel

+0

@dwenzel,你的來源是什麼?我確實想按照正確的Ember慣例出門。我已經研究過的一個示例項目具有上述的編輯方式,但不能保證它們正確。 –

+1

我認爲這只是一個REST API約定,儘管我找不到具體的源代碼。這似乎是合乎邏輯的:通常url就像一個嵌套的文件夾結構:'/ companies/edit ...'看起來像是在編輯所有公司,而'/ companies /:company_id/edit'看起來像是在編輯特定公司,這是你想要的。 – dwenzel