Reputation: 73235
I have an Ember project with the following router:
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('index', {path: '/'}, function() {
this.route('folder', {path: 'folder/:folder_id'});
});
});
export default Router;
The contents of routes/index/folder.js
are as follows:
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
console.log(params);
return this.store.query('message', {folder_id: params.folder_id});
}
});
My expectation is that when the route changes to /folder/1
, the model()
method will be invoked to fetch the messages for the folder.
However, this does not occur. The route indeed changes, but the model()
method is never invoked (nothing is written to the console).
What am I missing?
Upvotes: 0
Views: 46
Reputation: 3621
If I had to guess, you're using {{#link-to 'index.folder' aModel}}
and since a model is already provided, there's no need to fetch it again. If you did {{#link-to 'index.folder' aModel.id}}
it would trigger the model
hook again because a model is not provided.
You can see in this Twiddle that the model hook is called in your example with visiting the path folder/12
directly (not via link-to).
The Routing Guide goes into detail about this.
Upvotes: 2
Reputation: 91
Try to generate the route using ember cli from the command line:
ember g route folder
It will create all the files that you need in the proper place, and also edit router.js
accordingly.
This way I think you'll get a route that will answer to /folder
. Then change router.js
, adding the path for the route and hit /folder/1
. If nothing happens check the console for errors, it can be that the message
model doesn't exist.
Upvotes: 0