I am a beginner to Ember.js so I took the Codeschool course 'Try Ember'. So following this course I actually get an error.
My router.js
file looks like this:
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('orders', function(){
this.route('order', {path: '/:order_id'});
});
});
export default Router;
Now as far as I understand from the tutorial I have two routes orders.js
and order.js
with templates templates/orders.hbs
and templates/orders/order.hbs
respectively.
orders.js
file:
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return [
{ id: '1', name: 'Vlatko'},
{ id: '2', name: 'Mila'}
];
}
});
order.js
file:
import Ember from 'ember';
export default Ember.Route.extend({
model(params){
return [
{ id: '1', name: 'Vlatko'},
{ id: '2', name: 'Mila'}
].findBy('id', params.order_id);
}
});
templates/orders.hbs
file:
<h2>Hello from orders</h2>
<p>
Order
</p>
templates/orders/order.hbs
file:
<p>Order for </p>
So everything is pretty simple and works well, but when I try to do a full page reload(enter directly on the page) /orders/1
it raises two errors Error while processing route: orders.order No model was found for 'order' Error: No model was found for 'order'
and Error: No model was found for 'order'
. Now, I've searched a lot on the web and I can't find the same error.
An additional hint: This only happens when I use nested routes. If for instance I have something like this in my router.js
:
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('orders');
this.route('order', {path: '/orders/:order_id'});
});
export default Router;
I get not error. If this question has been asked before please don't downvote me and just point me to the answer and I will gladly delete it.
Aucun commentaire:
Enregistrer un commentaire