Answer the question
In order to leave comments, you need to log in
Why does Ember display data only after page reload?
Hello! Please help me figure it out.
Implemented a menu with categories on several pages of the site (as for me, a very clumsy method, if you tell me better - great):app/router.js
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function () {
this.route('index', { path: '/'});
this.route('catalog', function () {
this.route('category', { path: '/:category_id'});
});
this.route('products', function () {
this.route('product', { path: '/:product_id'});
});
});
export default Router;
index.js
and catalog/index.js
look identical:import Ember from 'ember';
export default Ember.Route.extend({
model () {
return Ember.RSVP.hash({
categories: this.store.findAll('category'),
products: this.store.findAll('product'),
});
}
});
catalog/category.js
import Ember from 'ember';
export default Ember.Route.extend({
model (params) {
return Ember.RSVP.hash({
category: this.store.findRecord('category', params.category_id),
categories: this.store.findAll('category'),
});
}
});
<[email protected]:category::ember579:1>
{ categories: <DS.RecordArray:ember377>, category: <[email protected]:category::ember576:1> }
Answer the question
In order to leave comments, you need to log in
When you click on a category in the catalog, the category model itself is passed as a model to the route (as you have app/router.js written), and the stage of loading the model is skipped, since the model is already there.
When you reload the page, the route model will load as it should since it's not a link.
That's why there are differences.
You need to pass in the link-to not the category model, but its id if you want the model to be always executed in the route.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question