I am new to EmberJS.
As per the Ember documentation,
A route with a dynamic segment will only have its model hook called when it is entered via the URL. If the route is entered through a transition (e.g. when using the link-to Handlebars helper), then a model context is already provided and the hook is not executed. Routes without dynamic segments will always execute the model hook.
Could you please explain the above with a simple example.
The url matching the 1st route would be /items while the url matching the child route would be /items/[some id]
β¦ where βsome idβ is the dynamic segment.
Note that the name of the child route is βitemβ, while the string in the url itself is the concatenation of the parent route. The name simply identifies in which route file to find the route logic.
When we load the 1st route, typically Ember will fetch a list of items β the index route. Also typically, the template will have something along the lines of:
{{#each model as |item|}}
{{#link-to "lists.list" item}}
<p>{{item.name}}</p>
{{/link-to}}
{{/each}}
This creates a list of links, one for each item. When we follow one of those links, Ember (or Ember-Data) will aready have a the appropriate item in its list of item models that had been fetched in the parent (index) route. Because Ember already has the object the model hook is not called.
However, if one were open the above link directly, the browser will make a direct request for the resource β/items/52β, so Ember will be forced to first deal with fetching the appropriate model.